我在从我正在开发的 .net 4.0 应用程序连接到 iseries DB2 数据库时遇到了一些困难。我一直在尝试使用 IBM.Data.DB2.dll 库通过以下代码连接到它;
String connectionString = "Database=[DBName];UserID=[UserID];Password=[Password];Server=[ServerName]";
connection = new DB2Connection(connectionString);
connection.Open();
当 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"("0100")"". SQLSTATE=58009
有人知道在 .net 中连接到这种数据库的另一种方法吗?
最佳答案
这对我有用:
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();
}
}
关于c# - 使用 .NET 连接到 iSeries DB2 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26103071/