Search code examples
c#entity-framework-corewebsphere.net-6.0informix

IBM Informix connection problem using IBM.EntityFrameworkCore


I'm trying to connect to an IBM Informix database using the official IBM Nuget library IBM.EntityFrameworkCore 6.0.300. When the connection is opened I'm getting an error:

Culture is not supported. (Parameter 'culture')
4096 (0x1000) is an invalid culture identifier.

My DbContext class is:

public class AppDbContext : DbContext
{
    public AppDbContext() : base() { }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseDb2
        (@"Host=10.216.1.6:1526;Server=my_server;Database=my_database;userid=my_user;password=*******", p => p.SetServerInfo(IBMDBServerType.IDS));
    }

    public DbSet<Flyer> Flyers => Set<Flyer>();
}

Any suggestion to resolve this?

EDIT:

The exception callstack is:

   at System.Globalization.CultureInfo..ctor(Int32 culture, Boolean useUserOverride)
   at IBM.Data.Db2.ODC.InvalidArgument()
   at IBM.Data.Db2.DB2ConnPool.ReplaceConnectionStringParms(DB2Connection connection, String szValue, DB2ConnSettings& pSettings, DB2ConnSettingsInternal& pSettingsInternal, Boolean bAttach, Boolean pushDownStrAppended)
   at IBM.Data.Db2.DB2Connection.set_ConnectionString(String value)
   at IBM.Data.Db2.DB2Connection..ctor(String connectionString)
   at IBM.EntityFrameworkCore.Storage.Internal.Db2SqlConnection.CreateDbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
   at IBM.EntityFrameworkCore.Storage.Db2RelationalCommand.CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.InitializeReader(Enumerator enumerator)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at WpfApp3.MainWindow..ctor() in C:\Users\guillermoec\source\repos\WpfApp3\WpfApp3\MainWindow.xaml.cs:line 31

EDIT #2:

I solved the problem related with the culture: I simply added the combination en_US as one of the computer languages and it worked. Before I had only installed fr_CH and en_CH languages.

Like comments say, the connection string is wrong. I changed it and now looks like this:

optionsBuilder.UseDb2(@"Server=10.216.1.6:1526;Database=my_database;user id=my_user;password=*******", p => {
                p.SetServerInfo(IBMDBServerType.IDS);
            });

But it still don't work, I get a new error:

ERROR [08001] [IBM] SQL30081N  A communication error has been detected. Communication protocol being used: "TCP/IP".  Communication API being used: "SOCKETS".  Location where the error was detected: "10.216.1.6".  Communication function detecting the error: "recv".  Protocol specific error code(s): "*", "*", "0".  SQLSTATE=08001

And stack trace:

   at IBM.Data.Db2.DB2ConnPool.Open(DB2Connection connection, String& szConnectionString, DB2ConnSettings& ppSettings, Object& ppConn)
   at IBM.Data.Db2.DB2Connection.Open()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternal(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.InitializeReader(Enumerator enumerator)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at WpfApp3.MainWindow..ctor() in C:\Users\guillermoec\source\repos\WpfApp3\WpfApp3\MainWindow.xaml.cs:line 33

I installed the Informix SDK 4.50 and configured a new ODBC data source for my DB. I tried to open a connection to the DB using the method IfxConnection from the library Informix.Net.Core.dll. I can connect to the database successfully using this connection string:

@"Host=10.216.1.6:1526;Server=instance_name;Database=my_database;User ID=my_userid;Password=*******"

The database version is 11.50, it could be related to the DB version?

Also we have other instances in the same machine, could this influence in the database connection?


Solution

  • Finally all my problems are solved and I want to share it with you. Maybe it can help someone with a similar problem.

    Technical background:

    • Our current applications are using ODBC to manage connections to the DB.
    • We want to create a new one using ASP NET Core and EntityFramework.
    • Our Informix ODBC driver is configured to use the default SQLI protocol (1). So our server is using the SQLI protocol.
    • The IBM.EntityFrameworkCore, internally uses the library Net.IBM.Data.Db2 to connect to the different RDBMS of IBM. This library uses de DRDA protocol to communicate with the database servers (1). This library not relies on ODBC.

    The solution was:

    According to this post, I asked our DBA to create a new listener for the protocol DRDA. After this and all firewall configurations, finally I got access to the database and the data stored on it.

    Regarding the problem with the culture, I tried to add the language en_US on the Windows configuration. After that the error related to the culture disappeared and I got a new connection error. So after I solved the connection error, I tried to remove the en_US language and, all stills working fine. So I think that really this configuration is not relevant for the library to work, my problem was always related to the communication protocol.

    (2): https://www.ibm.com/docs/en/informix-servers/12.10?topic=options-differences-between-net-providers