Search code examples
c#asp.net-mvcexceptiondb2ibm-midrange

iDB2InvalidConnectionStringException connecting to AS400 on new server


So we've got a setup with an ASP.NET MVC / C# web app running on a Windows Server and connecting to an AS400 (DB2 midrange) database, and everything's working fine.

But then when IT tried to set up a new server and moved the app over, suddenly it's giving a 500 error. To debug it we installed Visual Studio Community on that same server and I copied over the dev (pre-compiled) version of the app to run, and the first time it tried to reach the AS400, I get the following exception:

Type: IBM.Data.DB2.iSeries.iDB2InvalidConnectionStringException Message: "The ConnectionString property is invalid."

Type: System.TypeInitializationException
Message: "The type initializer for 'IBM.Data.DB2.iSeries.iDB2Constants' threw an exception.

Type: IBM.Data.DB2.iSeries.iDB2DCFunctionErrorException
Message: "An unexpected exception occurred.
Type: System.AccessViolationException, Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt..

I think I remember seeing this same error on a user's PC for a desktop app, too, a while back.

Any idea what the issue is?

All that's needed to obtain the exception is running the following:

var connectionString = "DataSource=as400.MYCOMPANY.com; UserID=FAKEUSERNAME; Password=FAKEPASSWORD; InitialCatalog=PRODTEST; DataCompression=True; CheckConnectionOnOpen=True; CharBitDataAsString=True; Naming = System";
var test = new IBM.Data.DB2.iSeries.iDB2Connection(connectionString);

Solution

  • Thanks to @mustaccio for the answer:

    At least in JDBC connection strings every property/value pair must be terminated with a semicolon, including the last one.

    Added a ; to the end of the connection string and it started working. I guess for some reason it allows it to be missing on an older configuration but not a new one.