“Fatal error encountered during command execution.” mysql-connector .net

烈酒焚心 提交于 2019-12-11 09:16:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!