I am trying to specify the default schema/instance as part of a connection string (or specific command) so it does not need to be part of the query.
OdbcConnection conn = new OdbcConnection("Driver={IBM DB2 ODBC DRIVER}; Database=myDB; Hostname=myHostName; Port=myPort; Protocol=TCPIP; Uid=myID; Pwd=myPW;");
OdbcCommand comm = new OdbcCommand("select count(*) from customers", conn);
conn.Open();
var value = comm.ExecuteScalar();
conn.Close();
Unfortunately this fails with the error:
ERROR [42S02] [IBM][CLI Driver][DB2] SQL0204N myID.customers is an undefined name. SQLSTATE=42704.
Notice it's using myID where the Schema/Instance should be. If I specify the schema/instance explicity:
OdbcCommand comm = new OdbcCommand("select count(*) from mySCHEMA.customers", conn);
it works as expected. I'd like to specify mySCHEMA as part of the Connection String, similar to "Initial Catalog" when using MS SQL Server.
After a bunch of experimentation and googling, I can't seem to figure it out. Any ideas?
Wow, this one was obvious. I just need CurrentSchema=mySCHEMA in the connection string.
For some reason I didn't connect that dot right away after working through http://www.connectionstrings.com/ibm-db2 (tried all sorts of variations like Schema, Default Schema, etc). Hopefully this helps someone in the future...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With