2

I have a method in C# which should get some data from mysql and then insert this data in another table.
The problem is that no matter what I try i get another datareader is open.
I tried using the using statement, but with no success, maybe I do it wrong.
How to do that?

public void MethodName(List<string> objects)
{
    foreach(string Object in objects){
        SQLActions.Initialize();
        SQLActions.SQL_Open();
        MySqlDataReader queryData = SQLActions.SQL_Query("SELECT...query...");

        MySqlDataReader objectsData = SQLActions.SQL_Query("Another select....");
        SQLActions.SQL_NonQuery("Insert...");
        while(queryData.Read()){
            SQLActions.SQL_NonQuery("Another Insert...");
        }
        SQLActions.SQL_Close();
    }
}
2
  • Some code would be very helpful. Commented May 27, 2013 at 7:16
  • Mention your code here. Commented May 27, 2013 at 7:16

1 Answer 1

2

You are probably using the same connection for the DataReader and the ExecuteNonQuery. This is not supported, according to MSDN: http://msdn.microsoft.com/en-us/library/haa3afyz(v=vs.80).aspx

Check this:

C# mySQL There is already an open DataReader associated

From Microsoft:

You should always call the Close method when you have finished using the DataReader object.

Sign up to request clarification or add additional context in comments.

2 Comments

I cheched that before and I'm not sure if this will help. I want to insert when the reading process is going. I will not be able to read if I close the connection.
Can I use two parallel connections?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.