ExecuteNonQuery requires an open and available Connection. The connection's
current state is closed.
Often, i mean a few times a day, the database is no longer reachable.
The appication pool must be reset to activate it again.
I believe after 30minutes it comes alive as well.
What is going on?
I can't find so now and then issues like this. 5 1172
How do you open the connection in the first place? It sounds like you
might be opening the connection once in your web app and leaving it
open...For better performance, you should be opening the Connection as
late as possible and closing it as soon as possible. A connection is an
expensive resource at both the client (web server) and database server
end, and built in connection pooling will help the creation and
disposal of these connections to be very fast.
I would write the code something like this:
' assuming the Command object has already been initialized,
' and its Connection property set
Try
cmd.Connection.Open
cmd.ExecuteNonQuery
Catch ex as Exception
' deal with the exception, or wrap it and throw it for someone else
to deal with
Finally
' Always try to close the connection, even if an exception has
occurred
Try
cmd.Connection.Close
Catch ex as Exception
' ignore any errors when attempting to close the connection
' it could already be closed
End Try
End Try
Mike
Edwin Knoppert wrote: ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
Often, i mean a few times a day, the database is no longer reachable. The appication pool must be reset to activate it again. I believe after 30minutes it comes alive as well.
What is going on? I can't find so now and then issues like this.
Xhead:
Some [minor] comments on your sample code.
1 - I see no reason to rethrow the exception, either deal with it (which
most people can't) or don't catch it at all. There's no advantage to
repackaging it.
2 - Your try inside the finally is dangerous. You are swallowing any
exceptions.. What if conenction.Close() caused an OutOfMemoryException or
ThreadAbortException? You should _never_ swallow exception unless you are
working in a global exception handler. Just check if it's closed and call
close (or better, check if it's nothing and called dispose). If the call to
dispose throws an exception, I'm ready to bet most applications would do
well to crash at this point.
Try
connection.Open
command.ExecuteNonQuery
Finally
if not connection is nothing then
connection.Dispose
end if
if not command is nothing then
command.Dispose
end if
end try
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"xhead" <xh******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com... How do you open the connection in the first place? It sounds like you might be opening the connection once in your web app and leaving it open...For better performance, you should be opening the Connection as late as possible and closing it as soon as possible. A connection is an expensive resource at both the client (web server) and database server end, and built in connection pooling will help the creation and disposal of these connections to be very fast.
I would write the code something like this:
' assuming the Command object has already been initialized, ' and its Connection property set Try cmd.Connection.Open cmd.ExecuteNonQuery Catch ex as Exception ' deal with the exception, or wrap it and throw it for someone else to deal with Finally ' Always try to close the connection, even if an exception has occurred Try cmd.Connection.Close Catch ex as Exception ' ignore any errors when attempting to close the connection ' it could already be closed End Try End Try
Mike
Edwin Knoppert wrote: ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
Often, i mean a few times a day, the database is no longer reachable. The appication pool must be reset to activate it again. I believe after 30minutes it comes alive as well.
What is going on? I can't find so now and then issues like this.
Thanks fellas, will try this tomorrow.
To me the garbage collection should fix this all imo.
Maybe my mistake.
Afaik the destroy of an object, should invoke any close as well isn't?
So the garbage collection terminating the object at some point should in
theory close the connections as well.
Maybe wishful thinking :)
Thanks,
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
schreef in bericht news:%2****************@TK2MSFTNGP11.phx.gbl... Xhead: Some [minor] comments on your sample code.
1 - I see no reason to rethrow the exception, either deal with it (which most people can't) or don't catch it at all. There's no advantage to repackaging it. 2 - Your try inside the finally is dangerous. You are swallowing any exceptions.. What if conenction.Close() caused an OutOfMemoryException or ThreadAbortException? You should _never_ swallow exception unless you are working in a global exception handler. Just check if it's closed and call close (or better, check if it's nothing and called dispose). If the call to dispose throws an exception, I'm ready to bet most applications would do well to crash at this point.
Try connection.Open command.ExecuteNonQuery Finally if not connection is nothing then connection.Dispose end if if not command is nothing then command.Dispose end if end try
Karl -- MY ASP.Net tutorials http://www.openmymind.net/
"xhead" <xh******@gmail.com> wrote in message news:11**********************@g44g2000cwa.googlegr oups.com... How do you open the connection in the first place? It sounds like you might be opening the connection once in your web app and leaving it open...For better performance, you should be opening the Connection as late as possible and closing it as soon as possible. A connection is an expensive resource at both the client (web server) and database server end, and built in connection pooling will help the creation and disposal of these connections to be very fast.
I would write the code something like this:
' assuming the Command object has already been initialized, ' and its Connection property set Try cmd.Connection.Open cmd.ExecuteNonQuery Catch ex as Exception ' deal with the exception, or wrap it and throw it for someone else to deal with Finally ' Always try to close the connection, even if an exception has occurred Try cmd.Connection.Close Catch ex as Exception ' ignore any errors when attempting to close the connection ' it could already be closed End Try End Try
Mike
Edwin Knoppert wrote: ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
Often, i mean a few times a day, the database is no longer reachable. The appication pool must be reset to activate it again. I believe after 30minutes it comes alive as well.
What is going on? I can't find so now and then issues like this.
I have a related question.
I wrote me a wrapper which returns a reader, can i still safely close the
connection object?
The function returns the reader object as return value.
A declared(dim) reader receives this return refer and i use it further.
"Edwin Knoppert" <in**@pbsoft.speedlinq.nl> schreef in bericht
news:dl**********@azure.qinip.net... Thanks fellas, will try this tomorrow. To me the garbage collection should fix this all imo. Maybe my mistake.
Afaik the destroy of an object, should invoke any close as well isn't? So the garbage collection terminating the object at some point should in theory close the connections as well.
Maybe wishful thinking :)
Thanks,
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> schreef in bericht news:%2****************@TK2MSFTNGP11.phx.gbl... Xhead: Some [minor] comments on your sample code.
1 - I see no reason to rethrow the exception, either deal with it (which most people can't) or don't catch it at all. There's no advantage to repackaging it. 2 - Your try inside the finally is dangerous. You are swallowing any exceptions.. What if conenction.Close() caused an OutOfMemoryException or ThreadAbortException? You should _never_ swallow exception unless you are working in a global exception handler. Just check if it's closed and call close (or better, check if it's nothing and called dispose). If the call to dispose throws an exception, I'm ready to bet most applications would do well to crash at this point.
Try connection.Open command.ExecuteNonQuery Finally if not connection is nothing then connection.Dispose end if if not command is nothing then command.Dispose end if end try
Karl -- MY ASP.Net tutorials http://www.openmymind.net/
"xhead" <xh******@gmail.com> wrote in message news:11**********************@g44g2000cwa.googlegr oups.com... How do you open the connection in the first place? It sounds like you might be opening the connection once in your web app and leaving it open...For better performance, you should be opening the Connection as late as possible and closing it as soon as possible. A connection is an expensive resource at both the client (web server) and database server end, and built in connection pooling will help the creation and disposal of these connections to be very fast.
I would write the code something like this:
' assuming the Command object has already been initialized, ' and its Connection property set Try cmd.Connection.Open cmd.ExecuteNonQuery Catch ex as Exception ' deal with the exception, or wrap it and throw it for someone else to deal with Finally ' Always try to close the connection, even if an exception has occurred Try cmd.Connection.Close Catch ex as Exception ' ignore any errors when attempting to close the connection ' it could already be closed End Try End Try
Mike
Edwin Knoppert wrote: ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.
Often, i mean a few times a day, the database is no longer reachable. The appication pool must be reset to activate it again. I believe after 30minutes it comes alive as well.
What is going on? I can't find so now and then issues like this.
I believe this topic answers my questrion: http://forums.asp.net/777619/ShowPost.aspx
Note that this part. forum has extensive faq's. http://forums.asp.net/13/ShowForum.aspx
"Edwin Knoppert" <in**@pbsoft.speedlinq.nl> schreef in bericht
news:dl**********@azure.qinip.net... I have a related question. I wrote me a wrapper which returns a reader, can i still safely close the connection object? The function returns the reader object as return value. A declared(dim) reader receives this return refer and i use it further. "Edwin Knoppert" <in**@pbsoft.speedlinq.nl> schreef in bericht news:dl**********@azure.qinip.net... Thanks fellas, will try this tomorrow. To me the garbage collection should fix this all imo. Maybe my mistake.
Afaik the destroy of an object, should invoke any close as well isn't? So the garbage collection terminating the object at some point should in theory close the connections as well.
Maybe wishful thinking :)
Thanks,
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> schreef in bericht news:%2****************@TK2MSFTNGP11.phx.gbl... Xhead: Some [minor] comments on your sample code.
1 - I see no reason to rethrow the exception, either deal with it (which most people can't) or don't catch it at all. There's no advantage to repackaging it. 2 - Your try inside the finally is dangerous. You are swallowing any exceptions.. What if conenction.Close() caused an OutOfMemoryException or ThreadAbortException? You should _never_ swallow exception unless you are working in a global exception handler. Just check if it's closed and call close (or better, check if it's nothing and called dispose). If the call to dispose throws an exception, I'm ready to bet most applications would do well to crash at this point.
Try connection.Open command.ExecuteNonQuery Finally if not connection is nothing then connection.Dispose end if if not command is nothing then command.Dispose end if end try
Karl -- MY ASP.Net tutorials http://www.openmymind.net/
"xhead" <xh******@gmail.com> wrote in message news:11**********************@g44g2000cwa.googlegr oups.com... How do you open the connection in the first place? It sounds like you might be opening the connection once in your web app and leaving it open...For better performance, you should be opening the Connection as late as possible and closing it as soon as possible. A connection is an expensive resource at both the client (web server) and database server end, and built in connection pooling will help the creation and disposal of these connections to be very fast.
I would write the code something like this:
' assuming the Command object has already been initialized, ' and its Connection property set Try cmd.Connection.Open cmd.ExecuteNonQuery Catch ex as Exception ' deal with the exception, or wrap it and throw it for someone else to deal with Finally ' Always try to close the connection, even if an exception has occurred Try cmd.Connection.Close Catch ex as Exception ' ignore any errors when attempting to close the connection ' it could already be closed End Try End Try
Mike
Edwin Knoppert wrote: > ExecuteNonQuery requires an open and available Connection. The > connection's > current state is closed. > > Often, i mean a few times a day, the database is no longer reachable. > The appication pool must be reset to activate it again. > I believe after 30minutes it comes alive as well. > > What is going on? > I can't find so now and then issues like this.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rami A. Kishek |
last post by:
Hi - this mysterious behavior with shelve is just about to kill me. I
hope someone here can shed some light. First of all, I have this piece
of code which uses shelve to save instances of some...
|
by: Joseph |
last post by:
I've encountered a DB2 error that seems to be quite serious. This is from
DB2 7.2.5 running on Windows 2000 Server. Here are the entries from
the db2diag.log file (with database name changed per...
|
by: xixi |
last post by:
i have a very serious memory problem, we have db2 udb v8.1 load on a
HP titanium machine with 4 G memory, it is 64bit machine, currently on
DB2 instance , i have three databases, but only one is...
|
by: Jonathan \(Pickles\) Sklan-Willis |
last post by:
Hi All,
This is what I want to do:
1. Build a database in Access with certain queries and a query form.
(DONE).
2. I now need to use the same form as a form in VB, this will be the front
page...
|
by: BBFrost |
last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net
2003. At first things were looking ok, now problems are starting to
appear.
So far ...
(1) ...
|
by: Sin |
last post by:
Hello everyone,
I'm totally stumped at how little info I can find in MSDN or on the web
concerning this. It's almost as if only microsoft personel hold the key to
these secrets or something!!!
...
|
by: hamishd |
last post by:
Hello,
In my application I create some large vectors to hold data. For
example:
std::vector<DataItemClass*MyData;
DataItemClass * DataItem;
for(i=0;i<SomeLargeLimit;i++){
DataItem = new...
|
by: vijay.db |
last post by:
Hi Team,
Very serious problem with my DB2 V8.1 Fixpack 6 running in AIX 5.1
machine. Every one hour my DB2 instance processes are killed and it's
going down. Several trap files are generated in...
|
by: Tomasz |
last post by:
Hello Developers!
I have an interesting problem using my custom MembershipProvider,
RoleProvider and Forms Authentication.
Both MembershipProvider and RoleProvider require session state, where...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |