c# - 使用 .NET 连接到 iSeries DB2 数据库

标签 c# .net db2 ibm-midrange

我在从我正在开发的 .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/

相关文章:

java - Hibernate 在多对多列表上创建别名

database - 如何了解 DB2 中的空闲连接?

c# - 获取子列表

c# - 私有(private) TestInitialize 方法未初始化对象

java - 使用 Java 在数据库中存储 IPv4 的最佳方式

.net - XPathNavigator.Select ("self::node()/../..[@numberOfLocationsAdded!=' 0']")

c# - .Net 内存跟踪中的 "TargetCore"是什么?

c# - 如何跨对象链处理事件?

c# - 如何在 Unity3D HoloLens 应用程序上检测 BLE 信标?

c# - 在 .NET 4.0 中加载 native DLL 时发生 BadImageFormatException