I am attempting to connect to an IBM DB2 database from a .NET 5 console application. This works fine against DB2 LUW in a local Docker instance, but fails when connecting to a z/OS mainframe instance.
Server:
Client:
Error:
IBM.Data.DB2.Core.DB2Exception (0x80004005): ERROR [57017] [IBM] SQL0332N Character conversion from the source code page "" to the target code page "" is not supported. SQLSTATE=57017
at IBM.Data.DB2.Core.DB2ConnPool.Open(DB2Connection connection, String& szConnectionString, DB2ConnSettings& ppSettings, Object& ppConn)
at IBM.Data.DB2.Core.DB2Connection.Open()
at <my code>
Connection string:
Database=<redacted>;User ID=<redacted>;Password=<redacted>;Server=<redacted>:448;Persist Security Info=True;CurrentSchema=<redacted>;Connect Timeout=30
Opening connection:
var connection = new DB2Connection(connectionString);
try
{
connection.Open();
}
catch (DB2Exception e)
{
logger.LogError("Unable to access DB2 instance");
logger.LogError(e.ToString());
throw new DbAccessAcception(e);
}
The DB user I am testing with is already in use by another .NET program to connect to this database, though that app is older (.NET Framework 3.5).
What I've tried:
DB2CODEPAGE
environment variable as well as the connection string CodePage
parameter; nothing changed the error messagedb2cli.exe
Now what? Is there somewhere I can/should be setting the DB2 server type? Eg, z/OS vs LUW? Note that I'm not using EntityFramework, just directly executing Commands on that Connection object (though the error comes before then).
We have solved the problem. There were two changes to make, which definitely complicated things.
DB2CODEPAGE
environment variable to 1208
CurrentSchema
connection string parameter to set the prefix for our SQL queries, but the prefix wasn't the actual schema, which broke the connection even when the right codepage was set, without a useful error message on the client. We removed that parameter and manually set the table prefix on our SQL queries.Making both those changes got the application working.
Connecting to the local Docker instance had worked because I had set an actual schema for that prefix, not realizing the prod instance was configured differently.
User contributions licensed under CC BY-SA 3.0