c# - Why is my SQL CLR stored proc call claiming I am not providing a parameter I am? -


in clr procedure have following method:

private static void endownershipforteam(long assetid, int teamid) {     const string storedprocedurename = @"up_removeassetownershipfromteam";      using (var connection = new sqlconnection("context connection=true"))     using (var command = new sqlcommand(storedprocedurename, connection))     {         command.parameters.addwithvalue("assetid", assetid);         command.parameters.addwithvalue("teamid", teamid);          connection.open();         command.executenonquery();     } } 

when run method called getting following error:

msg 6522, level 16, state 1, procedure cp_removeasset, line 0

a .net framework error occurred during execution of user-defined routine or aggregate "cp_removeasset":

system.data.sqlclient.sqlexception: procedure or function 'up_removeassetownershipfromteam' expects parameter '@assetid', not supplied.

system.data.sqlclient.sqlexception:

at system.data.sqlclient.sqlconnection.onerror(sqlexception exception, boolean breakconnection)

at system.data.sqlclient.sqlcommand.runexecutenonquerysmi(boolean sendtopipe)

at system.data.sqlclient.sqlcommand.internalexecutenonquery(dbasyncresult result, string methodname, boolean sendtopipe)

at system.data.sqlclient.sqlcommand.executenonquery()

at storedprocedures.endownershipforteam(int64 assetid, int32 teamid)

at storedprocedures.cp_removeasset(sqlint32 userid, sqlstring xaid)

since code supplying parameters (verified displaying output via sqlcontext.pipe.send() calls) why claiming i"m not supplying parameter am?

looks written, code instructing sql server try executing this:

up_removeassetownershipfromteam 

in other words, procedure no parameters supplied.

to wire parameters need either specify commandtype.storedprocedure, or wire command parameters explicitly:

// option 1 private static void endownershipforteam(long assetid, int teamid) {     const string storedprocedurename = @"up_removeassetownershipfromteam";      using (var connection = new sqlconnection("context connection=true"))     using (var command = new sqlcommand(storedprocedurename, connection))     {         command.commandtype = commandtype.storedprocedure;         command.parameters.addwithvalue("assetid", assetid);         command.parameters.addwithvalue("teamid", teamid);          connection.open();         command.executenonquery();     } }  // option 2 private static void endownershipforteam(long assetid, int teamid) {     const string sql = @"exec up_removeassetownershipfromteam @assetid, @teamid";      using (var connection = new sqlconnection("context connection=true"))     using (var command = new sqlcommand(sql, connection))     {         command.parameters.addwithvalue("@assetid", assetid);         command.parameters.addwithvalue("@teamid", teamid);          connection.open();         command.executenonquery();     } } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -