PC Review


Reply
Thread Tools Rate Thread

Data reader already open?

 
 
Brett
Guest
Posts: n/a
 
      28th Jan 2005
I'm using this code in VS .NET 2003

Code:
Me.SqlCmd_BlacklistUpdateStatus.CommandText =
"dbo.[SpamUpdateReport_blacklist]"
Me.SqlCmd_BlacklistUpdateStatus.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlCmd_BlacklistUpdateStatus.Connection = Me.cn2
Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
False, CType(0, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@messageid", System.Data.SqlDbType.Int,
4))
Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@subpart",
System.Data.SqlDbType.SmallInt, 2))
'


cn2.Open()

'loop through returned records
Dim drspfblacklist As SqlDataReader
drspfblacklist = SqlCmd_SpamUpdate_spfBlackUnprocessed.ExecuteReader()
While drspfblacklist.Read
At the while statement, I get a data ready already open for this connection
error. If I remove the line cn2.open(), I get an error about the connection
being closed. This should say that no other resource is using the
connection. What else could be wrong?

Thanks,
Brett


 
Reply With Quote
 
 
 
 
W.G. Ryan eMVP
Guest
Posts: n/a
 
      28th Jan 2005
If you just use Command.ExecuteReader() will that work? It looks like cn2
is already associated with SqlCmd_BlacklistUpdateStatus - but is there a
connection associated with SqlCmd_SpamUpdate_spfBlackUnprocessed.

Just to be sure, use a new SqlConnection (just for testing) using the same
connection string as cn2- but use this connection for the command you're
calling ExecuteReader against. See if this doesn't fix it.

Also, is it blowing up on the Read() line or is it the ExecuteReader line?

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Brett" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I'm using this code in VS .NET 2003
>
>
Code:
>
> Me.SqlCmd_BlacklistUpdateStatus.CommandText =
> "dbo.[SpamUpdateReport_blacklist]"
> Me.SqlCmd_BlacklistUpdateStatus.CommandType =
> System.Data.CommandType.StoredProcedure
> Me.SqlCmd_BlacklistUpdateStatus.Connection = Me.cn2
> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
> System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
> System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
> False, CType(0, Byte), CType(0, Byte), "",
> System.Data.DataRowVersion.Current, Nothing))
> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
> System.Data.SqlClient.SqlParameter("@messageid",
Code:
System.Data.SqlDbType.Int,
> 4))
> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
> System.Data.SqlClient.SqlParameter("@subpart",
> System.Data.SqlDbType.SmallInt, 2))
>         '
>
>
> cn2.Open()
>
> 'loop through returned records
> Dim drspfblacklist As SqlDataReader
> drspfblacklist = SqlCmd_SpamUpdate_spfBlackUnprocessed.ExecuteReader()
> While drspfblacklist.Read
> 

>
> At the while statement, I get a data ready already open for this

connection
> error. If I remove the line cn2.open(), I get an error about the

connection
> being closed. This should say that no other resource is using the
> connection. What else could be wrong?
>
> Thanks,
> Brett
>
>



 
Reply With Quote
 
Brett
Guest
Posts: n/a
 
      28th Jan 2005
SqlCmd_SpamUpdate_spfBlackUnprocessed is associated with cn2 by this line:
Me.SqlCmd_BlacklistUpdateStatus.Connection = Me.cn2

cn2 is only associated with Me.SqlCmd_BlacklistUpdateStatus.Connection. I
did a search on "cn2" and that is its only association.

I did create a new connection, "cn3", and associated it to
Me.SqlCmd_BlacklistUpdateStatus.Connection. Same error. It occurs on this
line:
drspfblacklist = SqlCmd_SpamUpdate_spfBlackUnprocessed.ExecuteReader()

It actually doesn't make it to the read.

Thanks,
Brett

"W.G. Ryan eMVP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If you just use Command.ExecuteReader() will that work? It looks like cn2
> is already associated with SqlCmd_BlacklistUpdateStatus - but is there a
> connection associated with SqlCmd_SpamUpdate_spfBlackUnprocessed.
>
> Just to be sure, use a new SqlConnection (just for testing) using the same
> connection string as cn2- but use this connection for the command you're
> calling ExecuteReader against. See if this doesn't fix it.
>
> Also, is it blowing up on the Read() line or is it the ExecuteReader line?
>
> --
> W.G. Ryan, MVP
>
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "Brett" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> I'm using this code in VS .NET 2003
>>
>>
Code:
>>
>> Me.SqlCmd_BlacklistUpdateStatus.CommandText =
>> "dbo.[SpamUpdateReport_blacklist]"
>> Me.SqlCmd_BlacklistUpdateStatus.CommandType =
>> System.Data.CommandType.StoredProcedure
>> Me.SqlCmd_BlacklistUpdateStatus.Connection = Me.cn2
>> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
>> System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
>> System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
>> False, CType(0, Byte), CType(0, Byte), "",
>> System.Data.DataRowVersion.Current, Nothing))
>> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
>> System.Data.SqlClient.SqlParameter("@messageid",
Code:
> System.Data.SqlDbType.Int,
>> 4))
>> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
>> System.Data.SqlClient.SqlParameter("@subpart",
>> System.Data.SqlDbType.SmallInt, 2))
>>         '
>>
>>
>> cn2.Open()
>>
>> 'loop through returned records
>> Dim drspfblacklist As SqlDataReader
>> drspfblacklist = SqlCmd_SpamUpdate_spfBlackUnprocessed.ExecuteReader()
>> While drspfblacklist.Read
>> 

>>
>> At the while statement, I get a data ready already open for this

> connection
>> error. If I remove the line cn2.open(), I get an error about the

> connection
>> being closed. This should say that no other resource is using the
>> connection. What else could be wrong?
>>
>> Thanks,
>> Brett
>>
>>

>
>



 
Reply With Quote
 
Brett
Guest
Posts: n/a
 
      28th Jan 2005
I am also doing this just above my sub() but before the class declaration:

Friend WithEvents sqlCmd_spf_Update As System.Data.SqlClient.SqlCommand
Friend WithEvents cnAs System.Data.SqlClient.SqlConnection
Friend WithEvents cn2 As System.Data.SqlClient.SqlConnection
Friend WithEvents cn3 As System.Data.SqlClient.SqlConnection
Friend WithEvents SqlCmd_BlacklistUpdateStatus As
System.Data.SqlClient.SqlCommand
Friend WithEvents SqlCmd_SpamUpdate_spfBlackUnprocessed As
System.Data.SqlClient.SqlCommand
Friend WithEvents SqlCmd_spamBlacklist_Insert As
System.Data.SqlClient.SqlCommand

Will the above effect anything?

Here's where this all started: I originally had everything in one form. It
worked fine. I needed to free up the form so I created a class file and put
all the database object code in the class file. I just cut and pasted the
code created from dragging and dropping into the form. I wasn't sure how
else to get database objects into the class file since these aren't
available on the toolbar. From the form, I push a button, which starts a
new thread for the class file.

Thanks,
Brett


"W.G. Ryan eMVP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If you just use Command.ExecuteReader() will that work? It looks like cn2
> is already associated with SqlCmd_BlacklistUpdateStatus - but is there a
> connection associated with SqlCmd_SpamUpdate_spfBlackUnprocessed.
>
> Just to be sure, use a new SqlConnection (just for testing) using the same
> connection string as cn2- but use this connection for the command you're
> calling ExecuteReader against. See if this doesn't fix it.
>
> Also, is it blowing up on the Read() line or is it the ExecuteReader line?
>
> --
> W.G. Ryan, MVP
>
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "Brett" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> I'm using this code in VS .NET 2003
>>
>>
Code:
>>
>> Me.SqlCmd_BlacklistUpdateStatus.CommandText =
>> "dbo.[SpamUpdateReport_blacklist]"
>> Me.SqlCmd_BlacklistUpdateStatus.CommandType =
>> System.Data.CommandType.StoredProcedure
>> Me.SqlCmd_BlacklistUpdateStatus.Connection = Me.cn2
>> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
>> System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
>> System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
>> False, CType(0, Byte), CType(0, Byte), "",
>> System.Data.DataRowVersion.Current, Nothing))
>> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
>> System.Data.SqlClient.SqlParameter("@messageid",
Code:
> System.Data.SqlDbType.Int,
>> 4))
>> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
>> System.Data.SqlClient.SqlParameter("@subpart",
>> System.Data.SqlDbType.SmallInt, 2))
>>         '
>>
>>
>> cn2.Open()
>>
>> 'loop through returned records
>> Dim drspfblacklist As SqlDataReader
>> drspfblacklist = SqlCmd_SpamUpdate_spfBlackUnprocessed.ExecuteReader()
>> While drspfblacklist.Read
>> 

>>
>> At the while statement, I get a data ready already open for this

> connection
>> error. If I remove the line cn2.open(), I get an error about the

> connection
>> being closed. This should say that no other resource is using the
>> connection. What else could be wrong?
>>
>> Thanks,
>> Brett
>>
>>

>
>



 
Reply With Quote
 
W.G. Ryan eMVP
Guest
Posts: n/a
 
      28th Jan 2005
Brett, I figured it was the Execute command causing the problem. I'm
thinking that your problem may be that you're trying to access an connection
or command created in one thread in another thread. Is that a possibility?

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Brett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am also doing this just above my sub() but before the class declaration:
>
> Friend WithEvents sqlCmd_spf_Update As

System.Data.SqlClient.SqlCommand
> Friend WithEvents cnAs System.Data.SqlClient.SqlConnection
> Friend WithEvents cn2 As System.Data.SqlClient.SqlConnection
> Friend WithEvents cn3 As System.Data.SqlClient.SqlConnection
> Friend WithEvents SqlCmd_BlacklistUpdateStatus As
> System.Data.SqlClient.SqlCommand
> Friend WithEvents SqlCmd_SpamUpdate_spfBlackUnprocessed As
> System.Data.SqlClient.SqlCommand
> Friend WithEvents SqlCmd_spamBlacklist_Insert As
> System.Data.SqlClient.SqlCommand
>
> Will the above effect anything?
>
> Here's where this all started: I originally had everything in one form.

It
> worked fine. I needed to free up the form so I created a class file and

put
> all the database object code in the class file. I just cut and pasted the
> code created from dragging and dropping into the form. I wasn't sure how
> else to get database objects into the class file since these aren't
> available on the toolbar. From the form, I push a button, which starts a
> new thread for the class file.
>
> Thanks,
> Brett
>
>
> "W.G. Ryan eMVP" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > If you just use Command.ExecuteReader() will that work? It looks like

cn2
> > is already associated with SqlCmd_BlacklistUpdateStatus - but is there

a
> > connection associated with SqlCmd_SpamUpdate_spfBlackUnprocessed.
> >
> > Just to be sure, use a new SqlConnection (just for testing) using the

same
> > connection string as cn2- but use this connection for the command you're
> > calling ExecuteReader against. See if this doesn't fix it.
> >
> > Also, is it blowing up on the Read() line or is it the ExecuteReader

line?
> >
> > --
> > W.G. Ryan, MVP
> >
> > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> > "Brett" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> >> I'm using this code in VS .NET 2003
> >>
> >>
Code:
> >>
> >> Me.SqlCmd_BlacklistUpdateStatus.CommandText =
> >> "dbo.[SpamUpdateReport_blacklist]"
> >> Me.SqlCmd_BlacklistUpdateStatus.CommandType =
> >> System.Data.CommandType.StoredProcedure
> >> Me.SqlCmd_BlacklistUpdateStatus.Connection = Me.cn2
> >> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
> >> System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
> >> System.Data.SqlDbType.Int, 4,
Code:
System.Data.ParameterDirection.ReturnValue,
> >> False, CType(0, Byte), CType(0, Byte), "",
> >> System.Data.DataRowVersion.Current, Nothing))
> >> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
> >> System.Data.SqlClient.SqlParameter("@messageid",
> > System.Data.SqlDbType.Int,
> >> 4))
> >> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
> >> System.Data.SqlClient.SqlParameter("@subpart",
> >> System.Data.SqlDbType.SmallInt, 2))
> >>         '
> >>
> >>
> >> cn2.Open()
> >>
> >> 'loop through returned records
> >> Dim drspfblacklist As SqlDataReader
> >> drspfblacklist = SqlCmd_SpamUpdate_spfBlackUnprocessed.ExecuteReader()
> >> While drspfblacklist.Read
> >> 

> >>
> >> At the while statement, I get a data ready already open for this

> > connection
> >> error. If I remove the line cn2.open(), I get an error about the

> > connection
> >> being closed. This should say that no other resource is using the
> >> connection. What else could be wrong?
> >>
> >> Thanks,
> >> Brett
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Brett
Guest
Posts: n/a
 
      29th Jan 2005
I created a new app from scratch. Started with a Form1 and Class1. Then
started copying and pasting from the old app into the Class1. Form1 only has
Start and End buttons. As I progressed through the copying/pasting,
everything worked fine. I reached a point where everything above the

While drspfblacklist.Read

statement was the same in both apps. The data reader error never appeared. I
figured this was good enough. The app works fine now to that point.

Now the question is, what exactly is wrong in the old app since the two apps
are more or less copies of each other. Finding out what is wrong in the old
app will very useful. It's not feasible to recontruct an app just to find a
bug. There must be a better way. Any suggestions on how I can start? Perhaps
just breaking down the old app?

Thanks,
Brett


"W.G. Ryan eMVP" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Brett, I figured it was the Execute command causing the problem. I'm
> thinking that your problem may be that you're trying to access an
> connection
> or command created in one thread in another thread. Is that a
> possibility?
>
> --
> W.G. Ryan, MVP
>
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "Brett" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I am also doing this just above my sub() but before the class
>> declaration:
>>
>> Friend WithEvents sqlCmd_spf_Update As

> System.Data.SqlClient.SqlCommand
>> Friend WithEvents cnAs System.Data.SqlClient.SqlConnection
>> Friend WithEvents cn2 As System.Data.SqlClient.SqlConnection
>> Friend WithEvents cn3 As System.Data.SqlClient.SqlConnection
>> Friend WithEvents SqlCmd_BlacklistUpdateStatus As
>> System.Data.SqlClient.SqlCommand
>> Friend WithEvents SqlCmd_SpamUpdate_spfBlackUnprocessed As
>> System.Data.SqlClient.SqlCommand
>> Friend WithEvents SqlCmd_spamBlacklist_Insert As
>> System.Data.SqlClient.SqlCommand
>>
>> Will the above effect anything?
>>
>> Here's where this all started: I originally had everything in one form.

> It
>> worked fine. I needed to free up the form so I created a class file and

> put
>> all the database object code in the class file. I just cut and pasted
>> the
>> code created from dragging and dropping into the form. I wasn't sure how
>> else to get database objects into the class file since these aren't
>> available on the toolbar. From the form, I push a button, which starts a
>> new thread for the class file.
>>
>> Thanks,
>> Brett
>>
>>
>> "W.G. Ryan eMVP" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > If you just use Command.ExecuteReader() will that work? It looks like

> cn2
>> > is already associated with SqlCmd_BlacklistUpdateStatus - but is there

> a
>> > connection associated with SqlCmd_SpamUpdate_spfBlackUnprocessed.
>> >
>> > Just to be sure, use a new SqlConnection (just for testing) using the

> same
>> > connection string as cn2- but use this connection for the command
>> > you're
>> > calling ExecuteReader against. See if this doesn't fix it.
>> >
>> > Also, is it blowing up on the Read() line or is it the ExecuteReader

> line?
>> >
>> > --
>> > W.G. Ryan, MVP
>> >
>> > www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
>> > "Brett" <(E-Mail Removed)> wrote in message
>> > news:%(E-Mail Removed)...
>> >> I'm using this code in VS .NET 2003
>> >>
>> >>
Code:
>> >>
>> >> Me.SqlCmd_BlacklistUpdateStatus.CommandText =
>> >> "dbo.[SpamUpdateReport_blacklist]"
>> >> Me.SqlCmd_BlacklistUpdateStatus.CommandType =
>> >> System.Data.CommandType.StoredProcedure
>> >> Me.SqlCmd_BlacklistUpdateStatus.Connection = Me.cn2
>> >> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
>> >> System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
>> >> System.Data.SqlDbType.Int, 4,
Code:
> System.Data.ParameterDirection.ReturnValue,
>> >> False, CType(0, Byte), CType(0, Byte), "",
>> >> System.Data.DataRowVersion.Current, Nothing))
>> >> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
>> >> System.Data.SqlClient.SqlParameter("@messageid",
>> > System.Data.SqlDbType.Int,
>> >> 4))
>> >> Me.SqlCmd_BlacklistUpdateStatus.Parameters.Add(New
>> >> System.Data.SqlClient.SqlParameter("@subpart",
>> >> System.Data.SqlDbType.SmallInt, 2))
>> >>         '
>> >>
>> >>
>> >> cn2.Open()
>> >>
>> >> 'loop through returned records
>> >> Dim drspfblacklist As SqlDataReader
>> >> drspfblacklist = SqlCmd_SpamUpdate_spfBlackUnprocessed.ExecuteReader()
>> >> While drspfblacklist.Read
>> >> 

>> >>
>> >> At the while statement, I get a data ready already open for this
>> > connection
>> >> error. If I remove the line cn2.open(), I get an error about the
>> > connection
>> >> being closed. This should say that no other resource is using the
>> >> connection. What else could be wrong?
>> >>
>> >> Thanks,
>> >> Brett
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem of adobe reader 8 using "Open Full Reader Search " Mike Windows XP General 1 26th Mar 2007 08:07 AM
how to collectly put data in each cell from magnetic card reader data Electron-Serve Depot Microsoft Excel Worksheet Functions 4 6th Nov 2006 05:21 AM
checking if data reader is open Smokey Grindle Microsoft ADO .NET 3 22nd May 2006 02:09 PM
Converting an Oracle Data Reader into a SQL Server Data Reader Microsoft ADO .NET 3 20th Dec 2003 05:21 PM
problem with assigning data from data reader to label control in web form mhnazly Microsoft ASP .NET 1 28th Oct 2003 12:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:18 AM.