Connecting to a DB2 database DB2 with .NET.
I am having difficulty connecting to a DB2 DB2 database from a .NET application I am developing. I tried to use the IBM.Data.DB2.dll library to connect to it using the following code;
String connectionString = "Database=[DBName];UserID=[UserID];Password=[Password];Server=[ServerName]";
connection = new DB2Connection(connectionString);
connection.Open();
When the command is executed connection.Open()
, I get the following error:
ERROR [58009] [IBM] SQL30020N The command or SQL could not be executed due to a syntax error in the communication data stream, which will affect the successful execution of subsequent commands and SQL statements: Reason code "0x124C" ("0100") "". SQLSTATE = 58009
Does anyone know of another way to connect to this database in .net?
+3
source to share
2 answers
This works for me:
class Program
{
static void Main(string[] args)
{
string connString = "DataSource=SYSTEM;UserID=USER;Password=PASSWORD";
iDB2Connection conn = new iDB2Connection(connString);
conn.Open();
string cmdString = "CRTPF FILE(TESTLIB/TESTNET) RCDLEN(100)";
string cmdText = "CALL QSYS.QCMDEXC('" + cmdString + "', " + cmdString.Length.ToString("0000000000") + ".00000" + ")";
iDB2Command cmd = new iDB2Command(cmdText, conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
}
}
+2
source to share