data reader error...

B

Brian Henry

I keep getting this error message...System.InvalidOperationException: There
is already an open DataReader associated with this Command which must be
closed first. at
System.Data.SqlClient.SqlInternalConnectionTds.ValidateConnectionForExecute(SqlCommand
command) at
System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String
method, SqlCommand command) at
System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean
async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method,
DbAsyncResult result) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior,
String method) at
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior
behavior) at
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior
behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior) at
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable) at BDB.AddressEditor.RedoData() in

It happens after I perform an executenonquery, then try to reload data into
a dataset based on the table i just used the non query on to insert a new
row into it... nothing in this is databound, why would i get this error? i
dont even use data readers in my program (i understand that ADO.NET does in
the background though) so how can i go about debugging this?
 
B

Brian Henry

Dim cmdAdd As New SqlClient.SqlCommand("BENESP_CARR_AddCarrier",
BDB.database.dbConnectionData)

cmdAdd.CommandType = CommandType.StoredProcedure

cmdAdd.Parameters.AddWithValue("@name", sPartnerName.Trim)

cmdAdd.Parameters.Add("@CarrierID", SqlDbType.BigInt)

cmdAdd.Parameters("@CarrierID").Direction = ParameterDirection.Output

cmdAdd.Parameters.AddWithValue("@Active", True)

cmdAdd.ExecuteNonQuery()

iCarrierID = DirectCast(cmdAdd.Parameters("@CarrierID").Value, Int64)

Debug.Write("New Business Partner Added: " & iCarrierID.ToString)

cmdAdd.Dispose()



that is my query executed then doign this....



Dim cmdGetPhoneNumbers As New SqlClient.SqlCommand(_SelectProc,
database.dbConnectionData)

Dim daSQLAdp As New SqlClient.SqlDataAdapter(cmdGetPhoneNumbers)

Dim PrimaryKey(0) As DataColumn

' sql command initialization stuff

cmdGetPhoneNumbers.Parameters.Add(_keyColumn, Data.SqlDbType.BigInt).Value =
_ItemID

cmdGetPhoneNumbers.CommandType = CommandType.StoredProcedure

dsPhone.Clear() ' make sure we have a clear data set before filling it with
data

daSQLAdp.Fill(dsPhone, "PhoneNumbers")

' set the primary key column so we can use it later

PrimaryKey(0) = dsPhone.Tables("PhoneNumbers").Columns("PhoneID")

dsPhone.Tables("PhoneNumbers").PrimaryKey = PrimaryKey



fails at the fill with that exception... no other data queries are done
beween the two sections
 
M

Marina Levit [MVP]

Have you tried running your program on different machines? Using a different
database server?

I couldn't see anything in the code you posted that would point to a
problem, and I haven't seen this error message when there wasn't in fact an
open datareader somewhere.
 
J

Jose

Hi Brian!

Did you get a solution to your problem? I receive the same error and don´t know what to do!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top