So I’m getting a fantastically descriptive error message of “Invalid Argument” when trying to hook up to a DB2 database. I can successfully connect to it using SQUirrel (and JDBC) using the JTopen JDBC driver with the connection string of “jdbc:as400://server;naming=system;errors=full;prompt=no”
Since the jdbc connection works, I know its a Db2.net connector issue. But the error message “Invalid Argument” frustrates any efforts into diagnosing where to begin.
string connStr = "server=server;uid=user;pwd=password";
using(DB2Connection conn=new DB2Connection(connStr))
{
conn.Open();
//System.ArgumentException: Invalid argument
// at IBM.Data.DB2.DB2ConnPool.ReplaceConnectionStringParms(DB2Connection connection, String szValue, DB2ConnSettings& pSettings, DB2ConnSettingsInternal& pSettingsInternal, Boolean bAttach)
// at IBM.Data.DB2.DB2Connection.set_ConnectionString(String value)
// at IBM.Data.DB2.DB2Connection..ctor(String connectionString)
// at AuroraDAL_ConnectionTests.DB2ConnectionTests.try1() in C:\Projects\...\DB2ConnectionTests.cs:line 31
// at AuroraDAL_ConnectionTests.DB2ConnectionTests.Execute() in C:\Projects\...\DB2ConnectionTests.cs:line 19
// at AuroraDAL_ConnectionTests.Program.Main(String[] args) in C:\Projects\...\Program.cs:line 20
}
Using the testconn20.exe within the DB2.net connector program files directory, I tried several options, taking the first connection string above, to then changing the shorthand keys to their longhand values, (uid changed to user id, pwd changed to password, etc)
testconn20 server=server;database=database;user id=userid;password=password
the result of that returns the same “Invalid Argument” exception eventually:
Step 1: Printing version info
.NET Framework version: 2.0.50727.5448
64-bit
DB2 .NET provider version: 9.0.0.2
Capability bits: ALLDEFINED
Build: 20090522
Factory for invairant name IBM.Data.DB2 verified
Elapsed: 0.089982
Step 2: Connecting using "server=-------;database=------;userid=------;password=------"
Invalid Argument Exception:
Connection string should be of the type 'Database=db2db; Server=mymachine:60000; User ID=db2user; Password=xxxxxxxx
Test failed.
Does anybody with some DB2 and C# have any suggestions as to what i’m doing wrong? THanks in advance.
It appears that IBMs site doesnt direct you to latest and greatest bits of their .net data connector. The problem was mostly solved by thoroughly looking for updates and finding their “Fix Central”. This is where they keep updates and hot fixes. However it was not easy to get the right package.