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 1185
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.ExecuteNonQ uery
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.Clos e() caused an OutOfMemoryExce ption or
ThreadAbortExce ption? 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.Execute NonQuery
Finally
if not connection is nothing then
connection.Disp ose
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.goo glegroups.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.ExecuteNonQ uery 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******** ********@TK2MSF TNGP11.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.Clos e() caused an OutOfMemoryExce ption or ThreadAbortExce ption? 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.Execute NonQuery Finally if not connection is nothing then connection.Disp ose 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.goo glegroups.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.ExecuteNonQ uery 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.sp eedlinq.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******** ********@TK2MSF TNGP11.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.Clos e() caused an OutOfMemoryExce ption or ThreadAbortExce ption? 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.Execute NonQuery Finally if not connection is nothing then connection.Disp ose 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.goo glegroups.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.ExecuteNonQ uery 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.sp eedlinq.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.sp eedlinq.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******** ********@TK2MSF TNGP11.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.Clos e() caused an OutOfMemoryExce ption or ThreadAbortExce ption? 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.Execute NonQuery Finally if not connection is nothing then connection.Disp ose 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.goo glegroups.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.ExecuteNonQ uery 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 class I define. It
works perfectly on an old machine (PII-400) running Python 2.2.1 under
RedHat Linux 8.0. When I try to run it under Python for windows ME on a
P-4 1.4 GHz, however, it keeps crashing on reading from the shelved file
the second...
|
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 my employer's
policy):
===============================================================================
2004-02-16-13.28.49.037000 Instance:DB2 Node:000
PID:3368(db2syscs.exe) TID:2920 Appid:*LOCAL.DB2.040216212729
database_utilities ...
|
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 being used, on
the same machine, i have an application server running connect to this
DB2 server, every day there are around 12 persons has connection
through the app server to db server, the database has 9 G data/index,
problem is in the morning...
|
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 and will additionally have the following functions on it: Print, Save
(CSV), Import (CSV).
3. On top of that the program will function - solely as a stand-alone
program. I want to be able to modify the fields from within Access and for
|
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) ComboBox.SelectedValue = db_value;
If the db_value was not included in the ComboBox value list the
ComboBox.SelectedIndex used to return -1, Now the very same code is
| |
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!!!
I'm currently writting a program in which there is a file/folder list which
mimics part of Explorer's list. I've got it pretty much cornered, but I
still have a couple of problems :
|
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 DataltemClass;
|
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 the db2 diag log
directory. Following the detailed entry in the db2diag.log:
2007-02-28-05.00.10.650672 Instance:****** Node:000
PID:2109578(db2agent (dbname) 0) TID:1
Appid:GA6DA619.C438.002D98045717
|
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 some
very important context data are stored during the Session_Start event. My
MembershipProvider and RoleProvider depend on this information.
It seems that authentication process works with no problems.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |