Db2

Db2

Connect with Db2, Informix, Netezza, open source, and other data experts to gain value from your data, share insights, and solve problems.

 View Only
  • 1.  DbProviderFactories.RegisterFactory parameters for Net.IBM.Data.Db2 for .NET 7.0

    Posted Wed May 24, 2023 11:03 AM

    Previously, for .NET Framework 4.8 I was able to use (something like) the following to register the IBM iSeries factory using C#:

    DbProviderFactories.RegisterFactory("IBM.Data.DB2.iSeries", "IBM.Data.DB2.iSeries.iDB2Factory, IBM.Data.DB2.iSeries, Version=12.0.0.0, Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26");
    

    I understand that to connect using .NET 7.0 I now need to use the Net.IBM.Data.Db2 drivers.

    What would be the equivalent parameter values for DbProviderFactories.RegisterFactory() for Net.IBM.Data.Db2? I can't seem to find it online.

    I have installed the Net.IBM.Data.Db2 NuGet package.

    Thanks



    ------------------------------
    Eric M
    ------------------------------


  • 2.  RE: DbProviderFactories.RegisterFactory parameters for Net.IBM.Data.Db2 for .NET 7.0

    Posted Wed May 24, 2023 11:43 AM

    Did you try something like this:

      DbProviderFactory factory = DbProviderFactories.GetFactory("IBM.Data.DB2");
      DbConnection conn = factory.CreateConnection();
      DbConnectionStringBuilder sb = factory.CreateConnectionStringBuilder();
    
      if( sb.ContainsKey( "Database" ) )
      {
         sb.Remove( "database" );
         sb.Add( "database", "SAMPLE" );
      }
    
      conn.ConnectionString = sb.ConnectionString;
    
      conn.Open();


    ------------------------------
    Jan Nelken
    ------------------------------



  • 3.  RE: DbProviderFactories.RegisterFactory parameters for Net.IBM.Data.Db2 for .NET 7.0

    Posted Thu May 25, 2023 09:42 AM

    Unfortunately with .NET 7.0 you cannot use DbProviderFactories.GetFactory() without manually registering the factory first.  Previously (.NET Framework 4.8) you could use DbProviderFactories.GetFactory() to get one of the ones already registered on the machine, but not anymore.  Therefore I'm still looking for the correct parameter values for DbProviderFactores.RegisterFactory().



    ------------------------------
    Eric M
    ------------------------------



  • 4.  RE: DbProviderFactories.RegisterFactory parameters for Net.IBM.Data.Db2 for .NET 7.0

    Posted Thu May 25, 2023 10:14 AM

    And this eample also does not help you?

    RegisterFactory(String, String)

    Registers a DbProviderFactory with the given assembly-qualified name under the specified invariant provider name.

    C#
    public static void RegisterFactory (string providerInvariantName, string factoryTypeAssemblyQualifiedName);

    Parameters

    providerInvariantName
    String

    The invariant provider name under which to register the provider.

    factoryTypeAssemblyQualifiedName
    String

    The assembly-qualified name for a DbProviderFactory.



    ------------------------------
    Jan Nelken
    ------------------------------



  • 5.  RE: DbProviderFactories.RegisterFactory parameters for Net.IBM.Data.Db2 for .NET 7.0

    Posted Mon May 29, 2023 11:53 AM

    Your suggestion gave me an idea.  Once I was able to straighten out the namespaces I was able to use this to get the values I was looking for:

    using IBM.Data.Db2;
    DbProviderFactories.RegisterFactory("Net.IBM.Data.DB2", DB2Factory.Instance);
    DataTable dt = DbProviderFactories.GetFactoryClasses();

    This provided me with the following for the factoryTypeAssemblyQualifiedName parameter:

    "IBM.Data.Db2.DB2Factory, IBM.Data.Db2, Version=7.0.0.200, Culture=neutral, PublicKeyToken=7c307b91aa13d208"

    Thanks for your help.

    Now I am getting the following on connection.Open():

    ERROR [58009] [IBM] SQL30020N  Execution of the command or SQL statement failed because of a syntax error in the communication data stream that will affect the successful execution of subsequent commands and SQL statements:  Reason Code "0x124C"("0209")"".  SQLSTATE=58009



    ------------------------------
    Eric M
    ------------------------------



  • 6.  RE: DbProviderFactories.RegisterFactory parameters for Net.IBM.Data.Db2 for .NET 7.0

    Posted Mon May 29, 2023 12:36 PM

    1. what and where you are connecting from?

    2. what and where you are connecting to?

    0x124C(0209)  sounds like DRDA syntax error or DRDA protocol error. Depending on answers from 1. and 2. above - it would be more appropriate to open a case with IBM Support. Can you capture relevant traces?



    ------------------------------
    Jan Nelken
    ------------------------------