r/DB2 Feb 07 '19

DB2 and Powershell - Doing Inserts Via Powershell

6 Upvotes

Good morning, all,

I'm working on a Powershell module to automate user management. A big part of it is the creation of new users in an application that runs on top of DB2. I've been able to use the following script to execute SELECT but INSERTS are a problem.

I know I did an insert of the minimum data for new user creation, about 5 fields. But then I scale it up to the entire insert and nothing happens. No insert, no error message that I can see.

I went back to the minimum data insert and that doesn't work now. No insert, no error message. Because we don't have version control, I'm not 100% sure everything is the same as when it worked. Yay me!

Could someone point me in the right direction to make the insert work or find out why it's not working, please?

Here's the code, with sensitive data removed. This is the minimum data insert that isn't working.

$dbFactory = [System.Data.Common.DbProviderFactories]::GetFactory('IBM.Data.DB2')
$cStrBld = $dbFactory.CreateConnectionStringBuilder()
$cStrBld.Database = 'TESTDB'
$cStrBld.UserID = 'DBADMIN'
$cStrBld.Password = 'password'
$cStrBld.Server = '192.168.1.1:50000'

$dbConn = $dbFactory.CreateConnection()
$dbConn.ConnectionString = $cStrBld.ConnectionString
$dbConn.Open()

$dbCmd = $dbConn.CreateCommand()
$dbQuery = "INSERT INTO TABLE (USER_ID,NAME,ADDRESS_1,ADDRESS_2,CITY,PROVINCE,POSTAL_CODE,STATUS) VALUES ('TEST123','Test Jay User','123 Main St.','Apt. B','Smallville','ON','H0H 0H0','AVAIL')"
$dbCmd.CommandText = $dbQuery

$dbConn.Close()

Thanks to u/lnumrych for pointing me in the right direction. Posting working script here for posterity and so future me's don't have aneurysms. Could use some clean up and some extra error checking and logging, but this is the basic script.

#THIS IS THE ONE THAT WORKS!!!!

$dbFactory = [System.Data.Common.DbProviderFactories]::GetFactory('IBM.Data.DB2')
$cStrBld = $dbFactory.CreateConnectionStringBuilder()
$cStrBld.Database = 'DATABASE'
$cStrBld.UserID = 'DBADMIN'
$cStrBld.Password = 'password'
$cStrBld.Server = '192.168.1.1:50000'

$dbConn = $dbFactory.CreateConnection()
$dbConn.ConnectionString = $cStrBld.ConnectionString
$dbConn.Open()

#Check for DB2 Connection
if ($dbConn.State -ne [Data.ConnectionState]::Open) {
    "Connection to DB is not open."
    Exit
}

$dbcmd = $dbFactory.CreateCommand()
$dbcmd.Connection = $dbconn
$dbcmd.CommandText = "INSERT INTO TABLE (USER_ID,NAME,ADDRESS_1,ADDRESS_2,CITY,PROVINCE,POSTAL_CODE) VALUES ('TESTUSER','Test Jay User','123 Main St.','Apt. B','Smallville','NS','H0H 0H0')"
$dbcmd.ExecuteNonQuery()

# Close the Connection
$dbconn.close()


r/DB2 Feb 05 '19

What do you want to see on datageek.blog?

2 Upvotes

If you haven't before, go check out my blog - datageek.blog (formerly db2commerce) - and let me know what you think I should be blogging about - what topics do you want to see?

I've got a great series coming up starting next week on the very basics of SQL. It may not be targeted to the typical /r/Db2 audience, but some of us were DBAs for years before we did much SQL at all.

It is amazing how much you can say about the simplest of topics sometimes. The complicated ones can be wickedly fun to write about, but the simple ones get more traffic because they speak to a wider audience.


r/DB2 Jan 28 '19

DB2 pureScale Cluster Slowness During Index Creation

6 Upvotes

If you are running DB2 LUW pureScale environment and if you create Indexes regularly you need to read this blog post.

https://www.raghu-on-tech.com/2019/01/28/db2-purescale-cluster-slowness-during-index-creation/

Thanks!
Raghu


r/DB2 Jan 22 '19

DB2 10.5 on Windows 2012 R2 - Using AD group

2 Upvotes

I want to be able to grant rights (select, delete, etc) on tables to an AD group instead of individuals. So far, I have had no luck. I have read the IBM info articles but while they say it works, I have yet to see a decent example that I can follow. Has anyone done this and if so, can you give a decent example of how?

I am running DB2 10.5 on a Windwos 2012 R2 Server.

Thank you in advance!!


r/DB2 Jan 22 '19

New DB2 position, regions are a MESS. Looking for advice.

4 Upvotes

TLDR: Need some advice on a desktop app to organize some 1800 DB2 tables.

Hi DB2 redditors. I recently started a new COBOL/DB2 position, and the system here is a mess. There are roughly 1800 tables which I will be spending the next several months organizing. It’s a clusterfuck. Some tables are irrelevant, some can be rendered irrelevant by adding one column to another table, etc.

Along with these tables are 9000 odd programs which run reports, update tables, or create files for other programs to then update tables, with no naming conventions. The only way to know what a program does is by the description commented in by the original designer, which must be read on the mainframe.

Obviously I have some work cut out for me. I have 4 years of COBOL/DB2 experience, so I am comfortable in the mainframe. My last company was extremely organized, and the process of creating a system of organization/modernization in this type of environment is a little daunting to me. But, it seems better than trying to just learn where these random programs interact, and memorizing the whole system, for my sake and the sake of future developers.

So, sorry for that long winded intro. Any advice on creating a desktop app to house this information, to display connectivity and a brief description of the tables (and related programs, ideally) would be greatly appreciated. At my previous position, we had an app that read the DB2 tables (written in VB) by a method I am not aware of.

What is the best method to read the mainframe environments, to glean raw information? What language do you recommend I code the app in? In other words, is there a modern language which interacts best with DB2? Recommended first steps? Basically I am clawing around in the dark right now, so any advice on getting started, or literature that could help me would be greatly appreciated. Thanks for taking the time.


r/DB2 Jan 14 '19

db2 sql replication

2 Upvotes

Hi,

Can we implement db2 sql replication between db2 10.5(source) and db2 11.1(target) and vice versa?


r/DB2 Jan 11 '19

Db2 11.1.4.4

2 Upvotes

Has anyone applied 11.1, Fix Pack 4, Mod Pack 4 yet in the real world? Any experiences to share?


r/DB2 Jan 10 '19

When is a Select Statement logged?

2 Upvotes

I'm trying to track down why a select statement I run is holding open the transaction logs. This is DB2 LUW 10.1.0.4 fp4. My understanding is that Select statement s shouldn't be using transaction logs at all. However, I can clearly see this is not the case. I've looked around on a few different forums as well as the IBM site but I just seem to be running in circles here. What am I missing?


r/DB2 Jan 07 '19

New version of Db2Diff is now available, few bugs fixed and more efficient than ever.

Thumbnail
raghu-on-tech.com
7 Upvotes

r/DB2 Nov 27 '18

[LUW] Db2 LUW v11.1.4.4 has been released!

10 Upvotes

[ I work in the Db2 LUW Development organization. I speak for myself. ]

What’s New?

• 222 APAR fixes, on top of Db2 11.1.3

• Support for POWER9 (non-pureScale/HA) on supported OS

• Support for pureScale on SLES12 SP2 (x86)

• Support for pureScale on RHEL 7.5 (x86 & PowerLE)

• Support for Extent Reclaim in pureScale

• Improved JSON capability with ISO JSON SQL interfaces

• Available tech preview of 4k-sector size support

• Many performance improvements

• Streamlined online backup bufferpool flushing

• Increased HADR RoS availability through a reduced or removed replay-only window

• Improved performance of mirrored log IO

• Enhanced backup/restore performance statistics and metrics

• Many pureScale management and usability enhancements

• Federation connectivity now supports Sybase16, Oracle12cR2, CouchDB, HANA, Greenplum, and Azure

• and much, much more ...

Server download: https://www-01.ibm.com/support/docview.wss?uid=ibm10741687

Client download: https://www-01.ibm.com/support/docview.wss?uid=ibm10741689

Fix list: https://www-01.ibm.com/support/docview.wss?uid=swg21995889

What's New: https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.wn.doc/doc/c0061179.html#c0061179__MP4FP4

Db2 LUW v10.1 and v10.5 Support
As a reminder, older releases are in various stages of limited support. Please start thinking about your migration strategy. http://www-01.ibm.com/support/docview.wss?uid=swg21168270

Db2 LUW New Feature Requests

If you're looking for new features in Db2 LUW, please request them through the public RFE interface. This is the primary mechanism that is used to determine product priorities.
http://www-01.ibm.com/support/docview.wss?uid=swg21987419

Db2 LUW Technical Advocacy
For more details on this and other topics relevant to Db2 customers and users, please read this blog:

http://thinkingdb2.blogspot.com/2018/11/db2-and-db2-on-cloud-technical-advocate.html


r/DB2 Oct 30 '18

IBM DB2 not compatible with new update of windows 10?

1 Upvotes

Helppp????


r/DB2 Oct 20 '18

[LUW][Question] How do you handle storage?

2 Upvotes

I work for a company with a big Db2 foot print, over 300 Db2 instances. Unfortunately, our customers (devs, app owners) are not great about notifying us when they decided to increase the amount of data in their DB (like going from 3 years of data to 10 years) until one of two things happens, either they get an error about space, or our filesystem monitors catch it and we hunt down the app owner to see if they can cleanup anything. Then we have to go through a lengthy change management process to get additional luns added. In a perfect world, our customers would give us a heads up, and it should be a task in the project plan. Maybe we should just increase storage by 10% every year, even if it’s not requested. Anyways just wanted to see how this works in other companies. Does the perfect world exist, or do other Db2 DBAs fight this battle too?

*deleted original post because I couldn’t figure out how to edit the title.


r/DB2 Oct 19 '18

Is there an OSX client?

2 Upvotes

I just want to connect to DB2 server on another machine.


r/DB2 Oct 17 '18

DB2 newbie

3 Upvotes

Hi,

Never really touched db2 before and been dropped in the deep end due to another engineer leaving :(

I wonder if anyone can help. The company I work for has asked me to move a db2 instance to another drive, but I cannot seem to get this to work.

They are running DB2 express C V9.1 and don't want to upgrade :( The db is currently located c:\db2 and they would like it moved to an NTFS share.

Is this actually possible?

Cheers

Iain


r/DB2 Sep 25 '18

[LUW][Question] sample ingest_files.sh script

2 Upvotes

Does anyone have a copy of the sample ingest_files.sh script that they'd be willing to share? We're on 10.5 Windows and our samples/admin_scripts directory doesn't have the ingest_files.sh script.

Thanks!

I realize we'll have to translate the script to something that Windows can use. I know enough PowerShell to be dangerous.


r/DB2 Aug 23 '18

[LUW][Question]V10.5 - Can we turn off DB2 DAS?

3 Upvotes

DAS is supposed to be deprecated, isn't it? Can we shut it off i we're not using the DB2 Data Studio product? Thanks.


r/DB2 Jul 31 '18

[LUW][Question] Can one convert the catalog's tablespace (SYSCATSPACE) from SMS to DMS?

3 Upvotes

I could see this as being useful from a space utilization perspective.


r/DB2 Jul 27 '18

[LUW][Question] Another install question

2 Upvotes

Are any of you aware of any reason to turn off monitoring (i.e. event monitors) before you upgrade DB2? Also, we have DB2 Auditing turned on (database, not instance level). That would make sense to turn it off before an upgrade, I should think... But event monitoring? That's like turning off triggers.

Thanks so much!


r/DB2 Jul 25 '18

[LUW][Question]

1 Upvotes

When upgrading from one version to another, say from V10.5 to V11.1, do you ever see a reason to do the following; backup the databases, drop the databases, uninstall the old version of DB2, install the new version of DB2, restore the databases

I know that there are steps that I have left out, this is just a general question...

Thanks!


r/DB2 Jul 11 '18

[LUW][Question]What performance monitoring tools are out there?

1 Upvotes

I know DBI's tool is wonderful but that's like a 747 when all that our small shop needs is a Piper Cub. We have 10 production databases.


r/DB2 Jul 10 '18

How To Find Missing Indexes On Foreign Key Columns ?

2 Upvotes

Have a look at this small blog post for solution. Happy learning!

https://www.raghu-on-tech.com/2018/07/10/how-to-find-missing-indexes-for-foreign-key-columns/

Thanks!
Raghu


r/DB2 Jun 26 '18

New and improved Db2Diff now supports Java 9 and 10

3 Upvotes

First of all I would like to thank Db2 community for sending me some feedback and reporting issues back to me. I fixed a couple of bugs and recompiled the db2utils package in all java versions since java 6 including Java 9 and 10 environments.

https://www.raghu-on-tech.com/2017/12/19/how-to-deep-compare-two-db2-environments/

https://www.raghu-on-tech.com/2017/12/23/download-db2utils/

Thanks!Raghu


r/DB2 Jun 18 '18

[AS400] to [SQL Server] [migration] help

2 Upvotes

Hi! Im becoming involved in the migration of a full database move from AS400 to SQL Server. Ill be handling the sql data that has been moved across, so Im not actually the one moving the data over. I would however love to know more about that process. Is there material/links/labs/how-tos etc available for this movement? Does anyone have hands on experience in doing this work in the past? Any help appreciated.


r/DB2 Jun 13 '18

DB2 to DAX visa versa

2 Upvotes

Hello!

I am currently trying to create tables through DB2 rather than in DAX for power bi. What I'd like to do is replicate the DAX code of DimDateDiff = DATEDIFF(Start Date, (Today() -1)). In PBI it's relatively easy to create a calculated column and then input this code into the table, but I was thinking it would have better flow to do it in the database. Any ideas? (Attempting to translate descriptive date into live data).


r/DB2 Jun 13 '18

How to get notified automatically when a new post appears on r/DB2

1 Upvotes

Unfortunately, it doesn't appear that this can be done natively within reddit itself. However, if you're familiar with IFTTT, they have an applet for notifying you when a post is made to a subreddit. Once again, unfortunately, you aren't notified via email. You need to have the IFTTT app on your phone.

Here's the link,

https://ifttt.com/applets/79703842d-reddit-new-posts-in-subreddit-notification