There is already an open DataReader Associated with this connection

Posts   
 
    
Baldev
User
Posts: 5
Joined: 10-Feb-2006
# Posted on: 10-Feb-2006 20:20:22   

I have c# windows application (.net 1.x) and i am using adapter. I have a Component one datagrid and i am using stored to get the data into datatable and using this datatable as datasource to datagrid. I then modify the grid and save the data to database using stored procedure. Some time on the last line that was updated i get an error message

There is already an open DataReader Associated with this connection which must be closed first.

I am not opening a datareader explicitly and i don't know internals of LLBLGen Object. All i am interested in is getting the data from database using stored procedure. if any readers are opened how to close those before i can make my insert statements.

thanks,

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39898
Joined: 17-Aug-2003
# Posted on: 10-Feb-2006 20:34:13   

You're using the dataaccessadapter in a multi-threaded environment? (so do you start new threads?)

How do you call the proc, by passing in an existing adapter?

Frans Bouma | Lead developer LLBLGen Pro
Baldev
User
Posts: 5
Joined: 10-Feb-2006
# Posted on: 10-Feb-2006 20:57:27   

thanks for prompt reply, i was ready to add another message so i could give a better picture of what i am doing.

I have windows application that has a main form and few other forms to perform some admin tasks. The Main form displays data from Open Jobs. User can update job quantity by click on buttons. But some data is refreshed on this main form after every 30 seconds using timer.

I have create a global data adapter that i am using to create my entities and my entity collections with in refreshData module. while the main form is open i am opening another form to filter jobs. This form has Component One's Flex grid. I use stored procedure to get data using my global adapter. I am not closing or re-initializing data adapter, adapter is created when user logs in to this application once. I then make modifications to grid and save this data for each line using stored procedure. This is where i get this error "There is already an open DataReader Associated with this connection". This happens only some times.

TimerFunctionMain Form () { Creates few Entity Collections to get data grids. Entity object to get some data for fields Some stored procedure calls }

FilterClick() { //on admin form while Main Form is still open System.Data.DataTable dt = RetrievalProcedures.Sp_PIPFilterJobs(sSelect, sWhere, sSort, SystemSettings.da);

DataColumn cAccumSAMS = new DataColumn("SAMSAccum",System.Type.GetType("System.Decimal")); DataColumn cAvailSAMS = new DataColumn("AvailableSAMS",System.Type.GetType("System.Decimal")); dt.Columns.Add(cAccumSAMS); dt.Columns.Add(cAvailSAMS); this.dgJobs.DataSource = dt; }

//SAVE GRID Generates error some times only. private void cmdSave_Click(object sender, System.EventArgs e) { for (int i=1; i < dgJobs.Rows.Count; i++) { C1.Win.C1FlexGrid.Row dr = dgJobs.Rows[i]; try { string sMsg = "UPDATE PIP_JOBS SET PriorityID = " + dr["PriorityID"].ToString() + ", CutlistSeq = " + dr["CutlistSeq"] + ""; //, SewDate" + sMsg = sMsg + " WHERE JobID = " + dr["JobID"].ToString(); PIPData.DatabaseSpecific.ActionProcedures.Sp_PIPExecuteSQL(sMsg, SystemSettings.da); } catch (Exception exp) { MessageBox.Show(exp.Message.ToString()); } } }

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 11-Feb-2006 17:07:48   

Set "KeepConnectionOpen" to false as a test. See manual "Generated code - DataAccessAdapter Functionality, Adapter --> Connection.

If this works then we can look for a 'programatic mehtod' which might be a bit more efficient.

Baldev
User
Posts: 5
Joined: 10-Feb-2006
# Posted on: 21-Feb-2006 22:45:39   

I had tried this setting "KeepConnectionOpen" to false and i still got same error few times. I had changed code to allow one thread to run process code at one time. I have not received so far.

2nd issue i have and may be there is already a solution to this somewhere in forum, the other day i was only able to see 4 threads.

Certain Combo boxes will display "System.Data.DataRowView" as data items. If i have 10 records returned by stored procedure i will see 10 of "System.Data.DataRowView" insted of actual data. I don't know why only on specific combo boxes. There are 3 on one form and only one of them is doing this. here is the code.

//displays "System.Data.DataRowView" dt = PIPData.DatabaseSpecific.RetrievalProcedures.Sp_PIPcboMod(); this.cboModID.ValueMember = "ModID"; this.cboModID.DisplayMember = "ModeCode"; this.cboModID.DataSource = dt;

//Displays the data properly dt = PIPData.DatabaseSpecific.RetrievalProcedures.Sp_PIPcboJobStatus(); this.cboJobStatusID.ValueMember = "JobStatusID"; this.cboJobStatusID.DisplayMember = "JobStatusDesc"; this.cboJobStatusID.DataSource = dt;

//STORED PROCEDURE CREATE PROCEDURE sp_PIPcboMod AS SELECT ModCode, ModID FROM PIP_MODS Order by ModCode GO

JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 22-Feb-2006 00:17:33   

Don't have a fix for you, but on a related note I noticed that you are using sp_ for your procs. Don't do that! At least when using SQL Server 2000 and below. Don't know about 2005.

Note If your stored procedure name begins with the "sp" prefix and is not in the master database, you see SP:CacheMiss before the cache hit for each execution even if you owner-qualify the stored procedure. This is because the sp prefix tells SQL Server that the stored procedure is a system stored procedure, and system stored procedures have different name resolution rules (the "preferred" location is in the master database). The names of user-created stored procedures should not begin with "sp_."

http://support.microsoft.com/default.aspx?scid=KB;en-us;q263889

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Feb-2006 07:32:07   

Did you debug to see if the dataTable returned from the SP call contains the correct data and structure that you expect?

Baldev
User
Posts: 5
Joined: 10-Feb-2006
# Posted on: 22-Feb-2006 14:41:09   

I had traced through my code and using Command window i checked the table

dt.Rows.Count 10

dt.Columns.Count 2

dt.Columns[0].ToString() "ModeID"

dt.Columns[1].ToString() "ModeCode"

this error should only popup when you set your ValueMember and DisplayMember to incorrect names. But i am not sure what is different when i set the field names manually VS dt.Columns[0].ToString()


THIS WORK FINE, HERE IS MY FIX


DataTable dt = PIPData.DatabaseSpecific.RetrievalProcedures.Sp_PIPcboMod(); this.cboModID.ValueMember = dt.Columns[0].ToString(); //ModeID this.cboModID.DisplayMember = dt.Columns[1].ToString(); //ModeCode this.cboModID.DataSource = dt;

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Feb-2006 15:34:48   

Check the fields Names in the LLBLGen Pro Designer or in the generated code.

Most probably the "ModID" would be generated as "ModId".

Baldev
User
Posts: 5
Joined: 10-Feb-2006
# Posted on: 22-Feb-2006 22:14:16   

I am not sure LLBLGen create list of all fields returned by select state from a stored procedure, i could not find either in LLBLGen app or generated code. When i looked at Immediate window in c#, it was showing proper name for columns. Also this is happening only on certain storedprocedures.

dt.Columns[0].ToString() "ModeID"

dt.Columns[1].ToString() "ModeCode"