How to Connect with a DB2 iseries database from Microsoft Azure?

0

I have a console application that execute a query over a db2 iseries database, the application runs fine in my laptop because I already have the drivers installed. The problem occurs when I want to execute the console application as a WebJob in Microsoft Azure, the console throw the following error:

[07/10/2018 15:14:54 > 32b9fb: SYS INFO] Status changed to Initializing

[07/10/2018 15:14:54 > 32b9fb: SYS INFO] Run script 'ConexionDB2.exe' with script host - 'WindowsScriptHost'

[07/10/2018 15:14:54 > 32b9fb: SYS INFO] Status changed to Running

[07/10/2018 15:14:55 > 32b9fb: ERR ]

[07/10/2018 15:14:55 > 32b9fb: ERR ] Unhandled Exception: IBM.Data.DB2.iSeries.iDB2InvalidConnectionStringException: The ConnectionString property is invalid. ---> System.TypeInitializationException: The type initializer for 'IBM.Data.DB2.iSeries.iDB2Constants' threw an exception. ---> IBM.Data.DB2.iSeries.iDB2DCFunctionErrorException: An unexpected exception occurred. Type: System.DllNotFoundException, Message: Unable to load DLL 'cwbdc.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E). ---> System.DllNotFoundException: Unable to load DLL 'cwbdc.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

[07/10/2018 15:14:55 > 32b9fb: ERR ] at IBM.Data.DB2.iSeries.CwbDc.DcDnGetConstants(MpDcConstants& parms)

[07/10/2018 15:14:55 > 32b9fb: ERR ] at IBM.Data.DB2.iSeries.CwbDc.GetConstants(MpDcConstants& parms)

[07/10/2018 15:14:55 > 32b9fb: ERR ] at IBM.Data.DB2.iSeries.iDB2Constants..cctor()

[07/10/2018 15:14:55 > 32b9fb: ERR ] --- End of inner exception stack trace ---

[07/10/2018 15:14:55 > 32b9fb: ERR ] at IBM.Data.DB2.iSeries.iDB2Constants..cctor()

[07/10/2018 15:14:55 > 32b9fb: ERR ] --- End of inner exception stack trace ---

[07/10/2018 15:14:55 > 32b9fb: ERR ] at IBM.Data.DB2.iSeries.iDB2ConnectionStringBuilder.set_Item(String keyword, Object value)

[07/10/2018 15:14:55 > 32b9fb: ERR ] at IBM.Data.DB2.iSeries.iDB2ConnectionStringBuilder.ParseConnectionString(String& propString, String& propertyInError, Exception& innerException)

[07/10/2018 15:14:55 > 32b9fb: ERR ] --- End of inner exception stack trace ---

[07/10/2018 15:14:55 > 32b9fb: ERR ] at IBM.Data.DB2.iSeries.iDB2Connection..ctor(String connectionString)

[07/10/2018 15:14:55 > 32b9fb: ERR ] at ConexionDB2.Program.Main(String[] args) in C:\Users\afcamacho\source\repos\ConexionDB2\ConexionDB2\Program.cs:line 14

[07/10/2018 15:14:55 > 32b9fb: SYS INFO] Status changed to Failed

[07/10/2018 15:14:55 > 32b9fb: SYS ERR ] Job failed due to exit code -532462766

I assume that the connection is not possible because there is no driver installed over microsoft azure.

This is my code:

string provider = "DataSource=10.0.0.0;userid=andres;password=123456;";

//Conexión
iDB2Connection cnn = new iDB2Connection(provider);
//Sentencia SQL
string sentencia = "select * from DTA.Customer FETCH FIRST 20 ROWS ONLY";

//Objeto contenedor de comandos
iDB2Command cmd = new iDB2Command(sentencia, cnn );

//Declaramos el objeto contenedor del resultado de ejecutar la sentencia
iDB2DataReader drDB2;

//Abrimos la conexión
cnn.Open();

//Creamos el objeto que va a contener el resultado de la sentencia SQL y cargamos los datos
drDB2 = cmd.ExecuteReader();

//Leemos los registros cargados
int i = 0;
while (drDB2.Read())
{
    Console.WriteLine(drDB2.GetString(i));
}
drDB2.Close();
cnn.Close();

Console.Read();

I also tried to install the "IBM.Data.DB.Provider" package in the project to connect the application to the db2 database but It doesn't work with the following code:

String cs = "Server=10.0.0.0;Database=DTA;UID=andres;PWD=123456;Connect Timeout=10";

DB2Command MyDB2Command = null;

DB2Connection MyDb2Connection = new DB2Connection(cs);

MyDb2Connection.Open();
MyDB2Command = MyDb2Connection.CreateCommand();
MyDB2Command.CommandText = "select * from DTA.customer FETCH FIRST 20 ROWS ONLY";
Console.WriteLine(MyDB2Command.CommandText);

DB2DataReader MyDb2DataReader = null;
MyDb2DataReader = MyDB2Command.ExecuteReader();
Console.WriteLine("============================");
while (MyDb2DataReader.Read())
{
    for (int i = 0; i <= 1; i++)
    {
        try
        {
            if (MyDb2DataReader.IsDBNull(i))
            {
                Console.Write("NULL");
            }
            else
            {
                Console.Write(MyDb2DataReader.GetString(i));
            }
        }
        catch (Exception e)
        {
            Console.Write(e.ToString());
        }
        Console.Write("\t");

    }
    Console.WriteLine("");
}
MyDb2DataReader.Close();
MyDB2Command.Dispose();
MyDb2Connection.Close();


Console.Read();

The above code throws this error:

en ConexionDB2.Program.Main(String[] args) en C:\Users\afcamacho\source\repos\ConexionDB2\ConexionDB2\Program.cs:línea 57IBM.Data.DB2.DB2Exception (0x80004005): 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.0.0.0". Communication function detecting the error: "selectForConnectTimeout". Protocol specific error code(s): "0", "", "". SQLSTATE=08001

Is there any way to connect .net to a DB2 database from an external server without the drivers?

Is there something wrong with the second code?

c#
db2
azure-webjobs
db2-400
asked on Stack Overflow Jul 10, 2018 by Andres Camacho

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0