jeudi 2 juin 2016

execute storedprocedure with one arg in server side and sql recognizes as two args

i'm currently trying to execute a stored procudure with one argument. the database is SQL Server 2005 and i am calling the sp from C# using OdbcCommand.

OdbcCommand oCmd = new OdbcCommand("{call sp_dominioMaquinas(?)}");
oCmd.Connection = new OdbcConnection(Config.Config.GetConnectionStringSqlConnection());

string psTipoExportarAux = "'" + psTipoExportar + "'";

oCmd.Parameters.Clear();
oCmd.Parameters.Add("@psTipoExportar", OdbcType.VarChar);
oCmd.Parameters["@psTipoExportar"].Value = psTipoExportarAux;

my problem is that my parameter psTipoExportar is a string with a coma (,) in it. (ex: a', 'b) and so sql server recognizes it as two parameters instead of one.

using a tool to see requests to my DB, I can see that my request is beeing misinterpreted (ex: exec sp_dom '''a'', ''b''') as two arguments when I want it to be processed as one.

if anyone could help out, that you

I'm following MSDN

and i've checked this questions here , here and here.

Aucun commentaire:

Enregistrer un commentaire