반응형
아래 코드가 있는데 예외가 발생합니다.
먼저 닫아야하는이
Connection
과 관련된 열린DataReader
가 이미 있습니다.
이 프로젝트에 Visual Studio 2010 / .Net 4.0 및 MySQL을 사용하고 있습니다. 기본적으로 데이터 리더를 사용하여 다른 작업을 수행하는 동안 다른 SQL 문을 실행하려고합니다. cmdInserttblProductFrance.ExecuteNonQuery ();
줄에서 예외가 발생합니다.
SQL = "Select * from tblProduct";
//Create Connection/Command/MySQLDataReader
MySqlConnection myConnection = new MySqlConnection(cf.GetConnectionString());
myConnection.Open();
MySqlCommand myCommand = new MySqlCommand(SQL, myConnection);
MySqlDataReader myReader = myCommand.ExecuteReader();
myCommand.Dispose();
if (myReader.HasRows)
{
int i = 0;
// Always call Read before accessing data.
while (myReader.Read())
{
if (myReader["frProductid"].ToString() == "") //there is no productid exist for this item
{
strInsertSQL = "Insert Into tblProduct_temp (Productid) Values('this istest') ";
MySqlCommand cmdInserttblProductFrance = new MySqlCommand(strInsertSQL, myConnection);
cmdInserttblProductFrance.ExecuteNonQuery(); //<=====THIS LINE THROWS "C# mySQL There is already an open DataReader associated with this Connection which must be closed first."
}
}
}
해결 방법
DataReader가 열려있는 동안 Connection이 사용 중입니다. exclusively by that DataReader. You cannot execute any commands for the Connection, including creating another DataReader, until the 원래 DataReader가 닫힙니다.
참조 페이지 https://stackoverflow.com/questions/5440168
반응형
'MySql' 카테고리의 다른 글
MySQL PostgreSQL 데이터베이스로 MySQL 덤프 가져 오기 (0) | 2020.10.13 |
---|---|
MySQL mysql에서 처음 10 개의 개별 행 선택 (0) | 2020.10.13 |
MySQL What column data type should I use for storing large amounts of text or html (0) | 2020.10.13 |
MySQL Python MySQLdb : connection.close () VS. cursor.close () (0) | 2020.10.13 |
MySQL Where does WAMP server store database files (0) | 2020.10.13 |
댓글