views:

48

answers:

1

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?

+2  A: 

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();
}
Darin Dimitrov
The problem was sqlStatement should have excluded the parms. Your post got me in the right direction. Thanks of the help!
Mike Wills
You may also check this post: http://www.netsplore.com/PublicPortal/blog.aspx?EntryID=30
Darin Dimitrov
As a matter to note, you might want to close your connection even if you have wrapped it in a using statement certain versions of the DB2 .NET assembly shipped by IBM did not close connections properly even if enclosed within a using block.
RandomNoob