Exception: "There is already an open DataReader associated with this Connection which must be closed first"
In this .NET project utilizing MySQL, Visual Studio 2010/.Net 4.0, an exception arises when attempting to execute an additional SQL statement while using a data reader. Specifically, the exception occurs at cmdInserttblProductFrance.ExecuteNonQuery();.
The root cause lies in the usage of the same connection for both the data reader and the ExecuteNonQuery method. According to MSDN, this is an unsupported practice:
"Note that while a DataReader is open, the Connection is in use exclusively by that DataReader. You cannot execute any commands for the Connection, including creating another DataReader, until the original DataReader is closed."
Updated 2018: Refer to the updated MSDN link for further information.
The above is the detailed content of Why Does `cmdInserttblProductFrance.ExecuteNonQuery()` Throw \'There is already an open DataReader associated with this Connection which must be closed first\'?. For more information, please follow other related articles on the PHP Chinese website!