【问题标题】:Problems with Executing a DB2 External Stored Procedure执行 DB2 外部存储过程的问题
【发布时间】:2010-07-06 19:20:30
【问题描述】:

我正在尝试调用外部存储过程(调用 RPG 程序)。我不断收到以下错误:

“异常详细信息:IBM.Data.DB2.iSeries.iDB2SQLErrorException:SQL0104 令牌@SSN 无效。有效令牌::.”

这是我的代码:

using (iDB2Connection conn = new iDB2Connection(_CONNSTRING))
{
    conn.Open();

    string sqlStatement = "MPRLIB.SIGNTIMESHEET (@SSN, @SIGNATURE, @WORKSTATION, @TOTALHOURS, @COMMENT)";
    //string sqlStatement = "MPRLIB.SIGNTIMESHEET (?, ?, ?, ?, ?)";

    iDB2Command cmd = conn.CreateCommand();
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = sqlStatement;
    cmd.Parameters.Add("@SSN", timesheet.EmployeeUniqueKey.ToString("0000000000"));
    cmd.Parameters.Add("@SIGNATURE", timesheet.EmployeeTypedName);
    cmd.Parameters.Add("@WORKSTATION", timesheet.EmployeeSignedComputer);
    cmd.Parameters.Add("@TOTALHOURS", GetJobHoursTotal(timesheet.Id).ToString("00000.000").Replace(".", ""));
    cmd.Parameters.Add("@COMMENT", timesheet.EmployeeComments);

    cmd.ExecuteNonQuery();
    conn.Close();
}

我似乎无法弄清楚发生了什么或为什么会出现上述错误。我的连接字符串如下所示:

private const string _CONNSTRING = "DataSource=192.168.50.200;DefaultCollection=QMFILES;Naming=sql;UserID=XXX;Password=XXX;";

可能是图书馆列表问题吗?该程序仅引用库列表中的一个文件。有什么建议吗?

【问题讨论】:

    标签: c# stored-procedures db2 ibm-midrange


    【解决方案1】:

    试试这样:

    using (var conn = new iDB2Connection(_CONNSTRING)) 
    using (var cmd = conn.CreateCommand())
    { 
        conn.Open();
    
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "MPRLIB.SIGNTIMESHEET";
        cmd.Parameters.Add("@SSN", timesheet.EmployeeUniqueKey.ToString("0000000000"));
        cmd.Parameters.Add("@SIGNATURE", timesheet.EmployeeTypedName);
        cmd.Parameters.Add("@WORKSTATION", timesheet.EmployeeSignedComputer);
        cmd.Parameters.Add("@TOTALHOURS", GetJobHoursTotal(timesheet.Id).ToString("00000.000").Replace(".", ""));
        cmd.Parameters.Add("@COMMENT", timesheet.EmployeeComments);
    
        cmd.ExecuteNonQuery();
    }
    

    【讨论】:

    • 问题是 sqlStatement 应该排除了参数。你的帖子让我朝着正确的方向前进。感谢您的帮助!
    • 你也可以查看这个帖子:netsplore.com/PublicPortal/blog.aspx?EntryID=30
    • 请注意,即使您已将连接包装在 using 语句中,您也可能希望关闭连接,IBM 提供的某些版本的 DB2 .NET 程序集即使包含在内也没有正确关闭连接在 using 块内。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 2021-01-30
    • 2020-05-27
    相关资源
    最近更新 更多