I know that for every data reader you need a new connection. So I've created 4 connections in the init() function for each of the datareaders. Its still giving me the error "There is already an Open DataReader Associated with this connection which must be closed first." Below is shortened version of my code. The Red Line is the one that keeps throwing the error. I could be going about this the wrong way.
Code:
public void init()
{
SQLConn = new SqlConnection(GetConnStr(DBN,"SQL1"));
SQLConn1 = new SqlConnection(GetConnStr(DBN,"SQL1"));
SQLConn2 = new SqlConnection(GetConnStr(DBN,"SQL1"));
SQLConn3 = new SqlConnection(GetConnStr(DBN,"SQL1"));
sqlComm = SQLConn.CreateCommand();
sqlComm1 = SQLConn1.CreateCommand();
sqlComm2 = SQLConn2.CreateCommand();
sqlComm3 = SQLConn3.CreateCommand();
}
public void dosomeFunc()
{
init();
SQLConn.Open();
SQLConn1.Open();
SQLConn2.Open();
SQLConn3.Open();
sqlComm.CommandText = "SELECT * FROM STUFF";
SqlDataReader drStuff = sqlComm.ExecuteReader();
while(drStuff.Read())
{
str = "SELECT * FROM OTHERSTUFF WHERE ID="+drStuff["ID"]
sqlComm1.CommandText = str;
SqlDataReader drOther = sqlComm1.ExecuteReader();
while(drOther.Read())
{
//dosomething;
}
drOther.Close();
}
drStuff.Close();
}
Thanks,
Josh