2

I am using MVC method and trying to connect to DB2. I have successfully got my connection string using Mysql but when I am going to connect to DB2 I am having this error message:

Exception thrown: 'System.ArgumentException' in IBM.Data.DB2.dll
An exception of type 'System.ArgumentException' occurred in IBM.Data.DB2.dll but was not handled in user code
Invalid argument

The error appears on my connection string code:

string constr = ConfigurationManager.ConnectionStrings["ConnStringDb2"].ConnectionString;
using (DB2Connection con = new DB2Connection(constr))

and here is my connection string setup from my web.config

  <connectionStrings>    
    <add name="ConnStringDb2" connectionString="DATABASE=DB;HOSTNAME=Myhost;PORT=50000;UID=user;PWD=pass;" />
  </connectionStrings>

I already installed the following:

IBM data client
IBM database add-ins

Is there any items that I am missing or need to add to my connection string or is the format for my connection is invalid. Any suggestion and comments. TIA.

Syntax Rommel
  • 932
  • 2
  • 16
  • 40

1 Answers1

2

According to DB2 connection string list, HOSTNAME and PORT configuration is used for OLE DB provider. For .NET Framework Data Provider usage, you should try one of these configurations below:

<!-- using hostname -->
<add name="ConnStringDb2" connectionString="SERVER=Myhost:50000;DATABASE=DB;UID=user;PWD=pass;" />

<!-- using server's IP address -->
<add name="ConnStringDb2" connectionString="SERVER=xxx.xxx.xxx.xxx:50000;DATABASE=DB;UID=user;PWD=pass;" />

If you currently use OLE DB provider, it is necessary to set DB2 provider name and protocol you're using to connect:

<add name="ConnStringDb2" connectionString="PROVIDER=IBMDADB2;DATABASE=DB;HOSTNAME=Myhost;PORT=50000;PROTOCOL=TCPIP;UID=user;PWD=pass;" />

Related issue: How to connect to DB2?

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61