Home > Database > Mysql Tutorial > Why Does `cmdInserttblProductFrance.ExecuteNonQuery()` Throw \'There is already an open DataReader associated with this Connection which must be closed first\'?

Why Does `cmdInserttblProductFrance.ExecuteNonQuery()` Throw \'There is already an open DataReader associated with this Connection which must be closed first\'?

Barbara Streisand
Release: 2024-12-09 22:22:15
Original
959 people have browsed it

Why Does `cmdInserttblProductFrance.ExecuteNonQuery()` Throw

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template