问题
I am using following code:
MySqlTransaction trnData = pconDB.BeginTransaction();
MySqlCommand cmdData = new MySqlCommand();
cmdData.Connection = pconDB;
cmdData.CommandTimeout = plngQueryTimeOut;
cmdData.CommandType = CommandType.Text;
cmdData.CommandText = "CALL spsOME( 4, 'DATA', 389552022,@intOutReturn);";
cmdData.Transaction = trnData;
plngRecordsCount = cmdData.ExecuteNonQuery();
Isn't CALL
statement possible directly from .net library? The same query is working on workbench.
回答1:
Change two lines to this:
cmdData.CommandType = CommandType.StoredProcedure;
cmdData.CommandText = "spsOME( 4, 'DATA', 389552022,@intOutReturn);";
You will also need to add a parameter to the Parameters collection of cmData
for the @intOutReturn
parameter. I won't give an example of this as the syntax varies with databases and I don't know what MySQL's looks like.
Also, this line:
cmdData.Transaction = trnData;
..is only necessary if you are doing other db operations which should be in the same transaction. If you're not, I'd leave that line out.
来源:https://stackoverflow.com/questions/24279926/fatal-error-encountered-during-command-execution-mysql-connector-net