"Executereader requires an open and available connection" error

  • Thread starter Thread starter karim
  • Start date Start date
K

karim

I have an asp.net page that stopped running properly giving the error
below. The app uses a SQL Server 2000 on another server. Enterprise Manager
and Query analyzer on the web server can connect to that sql server just
fine and run queries. I rebooted the web server and made aspnet member of
the admin group. I don't know why the error mentions open connections if I
can open several query anaylzer windows using the same sql server
credentials as the asp.net is using.
I suspect it's an issue with ado.net or .net in general.

Any ideas?

error message:
"Executereader requires an open and available connection

Karim
 
Sounds like you didn't open the connection. And you can't execute queries
before you open the connection.
 
Make sure you declared a Connection, ie SqlConnection cn =
new SqlConnection(myConnectionString)

Then, before executing the reader type either if(cn.State
<> ConnectionState.Open) { cn.Open} or just open it
without checking first ... cn.Open.

Since a lot of things can affect opening a connection, I'd
wrap that one line in a Try Catch Statement just to be
safe, b/c if you don't get a clean open, you don't need to
bother doing anything else. Trap the open problem and
respond accordingly.

Remember also that a 'connection' in this sense is a
connection object which opens a connectino to the database
if you tell it to and it's been set up properly. IT's
independent of Query Analyzer or EM.

Hopefully this helps.

Bill

W.G. Ryan
(e-mail address removed)
www.knowdotnet.com
 
Back
Top