2010-07-06 5 views
0

J'essaie d'appeler une procédure stockée externe (appelle un programme RPG). Je continue à obtenir l'erreur suivante:Problèmes liés à l'exécution d'une procédure stockée externe DB2

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

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

Je ne peux pas à comprendre ce qui se passe ou pourquoi je reçois l'erreur ci-dessus. Ma chaîne de connexion ressemble à:

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

Pourrait-il être un problème de liste de bibliothèque? Le programme référence simplement un fichier figurant dans la liste de bibliothèques. Aucune suggestion?

Répondre

3

Essayez comme ceci:

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

Le problème a été instructionSQL aurait dû exclure les parms. Votre message m'a amené dans la bonne direction. Merci de l'aide! –

+1

Vous pouvez également consulter ce post: http://www.netsplore.com/PublicPortal/blog.aspx?EntryID=30 –

+1

En fait, vous pouvez fermer votre connexion même si vous l'avez enveloppé dans un instruction Certaines versions de l'assembly DB2 .NET livrées par IBM n'ont pas fermé les connexions correctement même si elles étaient incluses dans un bloc using. – kd7

Questions connexes