执行 DB2 外部存储过程时出现的问题

发布于 2024-09-08 06:21:52 字数 1275 浏览 3 评论 0原文

我正在尝试调用外部存储过程(调用 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;";

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

I am trying to call an external stored procedure (calls an RPG program). I keep getting the following error:

"Exception Details: IBM.Data.DB2.iSeries.iDB2SQLErrorException: SQL0104 Token @SSN was not valid. Valid tokens: :."

Here is my code:

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();
}

I can't seem to figure out what is happening or why I am getting the above error. My connection string looks like:

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

Could it be a library list issue? The program just references one file that is in the library list. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追风人 2024-09-15 06:21:52

尝试这样:

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();
}

Try like this:

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文