"Reference"there is already a open DataReader associated with the This command raises the issue
I did not use DataReader in the statement, no hint of the same error, this DataReader hidden in where, I give you here, because I am not enough to study the depth, only know that there is a method of the call will generate DataReader, I think this is also the problem that most people have a headache.
When you use database updates or INSERT statements, you typically use the SqlCommand ExecuteNonQuery () method, and if you define a public database connection, this problem does not exist if you generate a new connection each time you query. However, the database occupies a much higher amount of resources, and after ExecuteNonQuery (), an empty DataReader object is generated internally, and the DataReader is released when the current database connection is closed. Therefore, when you use the Update method, it is recommended to use the Using keyword, which, as a statement, frees the objects within the scope that it defines.
1. The workaround is to add a parameter "multipleactiveresultsets" to ConnectionStringand set its value to true. X
server=192.168.9.24;database=flgl;user=sa;password=1231q2w34; Multipleactiveresultsets=true
2, the connection is not closed. The current state of the connection is connecting. √
using (Flglconn = new SqlConnection (FLGLCONNSTR))
{
SqlCommand cmd = new SqlCommand ();
DataSet ds = new DataSet ();
Cmd.commandtype = CommandType.StoredProcedure;
Cmd.commandtext = procname;
if (ParamArray! = null)
Cmd. Parameters.addrange (ParamArray);
Try
{
With SqlDataAdapter you don't have to write Conn.Open () and Conn.close (), which is superfluous.
Cmd. Connection = Flglconn;
SqlDataAdapter SDA = new SqlDataAdapter (cmd);
Sda. Fill (DS);
}
catch (Exception ex)
{
Log.writeerrorlog (ex. Message + ex. Source + "--The SQL statement is:" + procname);
}
Finally
{
Flglconn.close ();
}
return DS;
}
C#.net MySQL There is already a open DataReader associated with the This command raises the issue