473,385 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

SQL Connections with VB.NET

As most of you are aware, when you close a VB.NET connectrion to a SQL
server, the connection doesn't actually drop right then and there.
From my tests, using VB.NET 2003 and SQL2K, the connection doesn't
timeout and drop off for 6 1/2 minutes. How can one force this
connection to immediately drop off with code?

Jul 23 '05 #1
12 3223
This is called connection pooling. It is a good thing, why would you want to
get rid of it?

"Joe Cool" <jo*****@home.net> wrote in message
news:qj********************************@4ax.com...
As most of you are aware, when you close a VB.NET connectrion to a SQL
server, the connection doesn't actually drop right then and there.
From my tests, using VB.NET 2003 and SQL2K, the connection doesn't
timeout and drop off for 6 1/2 minutes. How can one force this
connection to immediately drop off with code?

Jul 23 '05 #2
I don't believe there is a way within .NET's CLR to clear the connection
pool in ADO.NET 1.x (which would close the actual SQL Server connection);
I've read that this should be available in 2.0, but I don't know if that is
the case.

Is there a reason you need to force the full SQL Server disconnect?
"Joe Cool" <jo*****@home.net> wrote in message
news:qj********************************@4ax.com...
As most of you are aware, when you close a VB.NET connectrion to a SQL
server, the connection doesn't actually drop right then and there.
From my tests, using VB.NET 2003 and SQL2K, the connection doesn't
timeout and drop off for 6 1/2 minutes. How can one force this
connection to immediately drop off with code?

Jul 23 '05 #3
On Wed, 01 Jun 2005 17:07:39 GMT, Joe Cool <jo*****@home.net> wrote:

¤ As most of you are aware, when you close a VB.NET connectrion to a SQL
¤ server, the connection doesn't actually drop right then and there.
¤ From my tests, using VB.NET 2003 and SQL2K, the connection doesn't
¤ timeout and drop off for 6 1/2 minutes. How can one force this
¤ connection to immediately drop off with code?

Not sure which provider or driver you are using with SQL Server but you could probably disable
connection pooling, although I wouldn't recommend it.
Paul
~~~~
Microsoft MVP (Visual Basic)
Jul 23 '05 #4
On Wed, 1 Jun 2005 13:49:16 -0400, "Marina" <so*****@nospam.com>
wrote:
This is called connection pooling. It is a good thing, why would you want to
get rid of it?

"Joe Cool" <jo*****@home.net> wrote in message
news:qj********************************@4ax.com.. .
As most of you are aware, when you close a VB.NET connectrion to a SQL
server, the connection doesn't actually drop right then and there.
From my tests, using VB.NET 2003 and SQL2K, the connection doesn't
timeout and drop off for 6 1/2 minutes. How can one force this
connection to immediately drop off with code?


As you and others have asked "Why?" here's the answer. I am developing
a VB.NET application that uses SQL as the database backend and I check
the existance of all required tables when the application starts. If
any tables are missing, I assume the database is corrupt and give the
user the option of deleting the current corrupt database and
recreating it. I open a connection to scan the database for the
requied tables and iof the user wants to start over, I would like to
close the connection and immediately open a connection to the master
database and drop the application database. But with connection
pooling, it appears that I will have to wait for 6 1/2 minutes (in my
case) before I can do that. I would prefer to not have to wait.

Yes, connection pooling is a good thing, but I would like to
temporarily disable it in this case.

Jul 23 '05 #5
Joe Cool (jo*****@home.net) writes:
As you and others have asked "Why?" here's the answer. I am developing
a VB.NET application that uses SQL as the database backend and I check
the existance of all required tables when the application starts. If
any tables are missing, I assume the database is corrupt and give the
user the option of deleting the current corrupt database and
recreating it. I open a connection to scan the database for the
requied tables and iof the user wants to start over, I would like to
close the connection and immediately open a connection to the master
database and drop the application database. But with connection
pooling, it appears that I will have to wait for 6 1/2 minutes (in my
case) before I can do that. I would prefer to not have to wait.


No, you don't have to wait. If the credentials are the same you don't
even have to change connection, just issue "USE master". If you have
different credentials, or want a new connection anyway, issue a
"USE tempdb" on the old connection before you close it, so that the
"DROP DATABASE" command is not blocked. Yet another possibility is
to issue "ALTER DATABASE db SET SINGLE_USER WITH ROLLBACK IMMEDIATE"
before you drop the database. That will kick out the connections
that lingers around.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #6
We had to disable connectioning pooling on our ASP.Net 2002 and ASP.Net
framework 2003 applications becuase we got intermittent errors about
the connectionpool running out and there was no actual way to get rid
of it.

For the record we were closing and disposing of out connection objects
properly but despite this, we would get the dreaded erorr unexpectedly,
and have to reset the server to sort it out.

Jul 23 '05 #7

"Joe Cool" <jo*****@home.net> wrote in message
news:a0********************************@4ax.com...
On Wed, 1 Jun 2005 13:49:16 -0400, "Marina" <so*****@nospam.com>
wrote:
As you and others have asked "Why?" here's the answer. I am developing
a VB.NET application that uses SQL as the database backend and I check
the existance of all required tables when the application starts. If
any tables are missing, I assume the database is corrupt and give the
user the option of deleting the current corrupt database and
recreating it. I open a connection to scan the database for the
requied tables and iof the user wants to start over, I would like to
close the connection and immediately open a connection to the master
database and drop the application database. But with connection
pooling, it appears that I will have to wait for 6 1/2 minutes (in my
case) before I can do that. I would prefer to not have to wait.

Yes, connection pooling is a good thing, but I would like to
temporarily disable it in this case.
As Erland points out, you can do what you want w/o disabling connection
pooling.

But, my greater question is... while it may be "nice" you're checking for a
corrupt db, is this really worth it?

I mean SQL Server is fairly stable and if you're having this as a common
problem, you've got other issues to deal with.

Also, if the DB is corrupt, as a user, I'd probably want to RESTORE it from
a backup, not lose all my existing data.

I'll assume you have your reasons here, but I am curious.


Jul 23 '05 #8
On Wed, 1 Jun 2005 21:47:33 +0000 (UTC), Erland Sommarskog
<es****@sommarskog.se> wrote:
Joe Cool (jo*****@home.net) writes:
As you and others have asked "Why?" here's the answer. I am developing
a VB.NET application that uses SQL as the database backend and I check
the existance of all required tables when the application starts. If
any tables are missing, I assume the database is corrupt and give the
user the option of deleting the current corrupt database and
recreating it. I open a connection to scan the database for the
requied tables and iof the user wants to start over, I would like to
close the connection and immediately open a connection to the master
database and drop the application database. But with connection
pooling, it appears that I will have to wait for 6 1/2 minutes (in my
case) before I can do that. I would prefer to not have to wait.


No, you don't have to wait. If the credentials are the same you don't
even have to change connection, just issue "USE master". If you have
different credentials, or want a new connection anyway, issue a
"USE tempdb" on the old connection before you close it, so that the
"DROP DATABASE" command is not blocked. Yet another possibility is
to issue "ALTER DATABASE db SET SINGLE_USER WITH ROLLBACK IMMEDIATE"
before you drop the database. That will kick out the connections
that lingers around.


Thanks. Very good info.

Jul 23 '05 #9
On Thu, 02 Jun 2005 01:25:56 GMT, "Greg D. Moore \(Strider\)"
<mo****************@greenms.com> wrote:

"Joe Cool" <jo*****@home.net> wrote in message
news:a0********************************@4ax.com.. .
On Wed, 1 Jun 2005 13:49:16 -0400, "Marina" <so*****@nospam.com>
wrote:
As you and others have asked "Why?" here's the answer. I am developing
a VB.NET application that uses SQL as the database backend and I check
the existance of all required tables when the application starts. If
any tables are missing, I assume the database is corrupt and give the
user the option of deleting the current corrupt database and
recreating it. I open a connection to scan the database for the
requied tables and iof the user wants to start over, I would like to
close the connection and immediately open a connection to the master
database and drop the application database. But with connection
pooling, it appears that I will have to wait for 6 1/2 minutes (in my
case) before I can do that. I would prefer to not have to wait.

Yes, connection pooling is a good thing, but I would like to
temporarily disable it in this case.


As Erland points out, you can do what you want w/o disabling connection
pooling.

But, my greater question is... while it may be "nice" you're checking for a
corrupt db, is this really worth it?

I mean SQL Server is fairly stable and if you're having this as a common
problem, you've got other issues to deal with.

Also, if the DB is corrupt, as a user, I'd probably want to RESTORE it from
a backup, not lose all my existing data.

I'll assume you have your reasons here, but I am curious.

I just don't trust the user not go go mucking around with the
Enterprise Manager and accidentally screwing something up.

Jul 23 '05 #10
MrDom (mr*******@hotmail.com) writes:
We had to disable connectioning pooling on our ASP.Net 2002 and ASP.Net
framework 2003 applications becuase we got intermittent errors about
the connectionpool running out and there was no actual way to get rid
of it.

For the record we were closing and disposing of out connection objects
properly but despite this, we would get the dreaded erorr unexpectedly,
and have to reset the server to sort it out.


Nevertheless, it's was a hole in your application, not in ADO .Net. If
memory serves, I think the common error is to not close the command
object before you close the connection.

Bill Vaugbn had some good articles on the ADO .Net connection pool
in the May and July 2003 issues of SQL Server Magazine. See
http://www.windowsitpro.com/Article/...356/38356.html and
http://www.windowsitpro.com/Article/...031/39031.html.
(The second article is for subscribers only, but the first is
publically available.)

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #11

"Joe Cool" <jo*****@home.net> wrote in message
news:ie********************************@4ax.com...

I just don't trust the user not go go mucking around with the
Enterprise Manager and accidentally screwing something up.
Agreed, but that doesn't really answer any of my questions. :-)


Jul 23 '05 #12
On Fri, 03 Jun 2005 00:29:53 GMT, "Greg D. Moore \(Strider\)"
<mo****************@greenms.com> wrote:

"Joe Cool" <jo*****@home.net> wrote in message
news:ie********************************@4ax.com.. .

I just don't trust the user not go go mucking around with the
Enterprise Manager and accidentally screwing something up.


Agreed, but that doesn't really answer any of my questions. :-)


Well, it did any the one question you aasked but it didn't address
your recommendation of simply restoring from a backup rather than
losing all the current data, and I do agree with that. IF the user had
bothered to make a backup.

Jul 23 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Randell D. | last post by:
Folks, I currently connect to my db with PHP code that uses non-persistent connections. I've read that persistent connections can help performance since a connection to the db will use an...
3
by: Mudge | last post by:
Hi, My hosting provider only allows me to use 50 connections to my MySQL database that my Web site will use. I don't know what this 50 connections means exactly. Does this mean that only 50...
4
by: Angelos | last post by:
I get this error mysql_pconnect Too many connections ... every now and then. Does anyone knows where it comes from ? There are a lot of sites running on the server and all of them use the...
1
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and...
2
by: Bob | last post by:
We have a production web site that's data intensive (save user input to DB and query for displaying) with the ASP.NET app part on one W2K server and SQL 2000 DB on another W2K server. I have set...
17
by: Peter Proost | last post by:
Hi Group, I've got an interesting problem, I don't know if this is the right group but I think so because everything I've read about it so far says it's a .net problem. Here's the problem, we're...
4
by: elyob | last post by:
Not really tried going two ways at once, but I have an include_once connection to a mysql_database, now I need to retrieve info from a second mysql_database .. My mysql_connects are getting...
1
by: marcfischman | last post by:
Please help. I have a website running on a linux/apache/mysql/php server. I receive about 8,000-10,000 visitors a day with about 200,000 to 300,000 page views. The server is a RedHat Linux...
13
by: PRP | last post by:
Hi, Our DBA has complained about the large number of connections from the aspnet_wp process. We have multiple web applications deployed in different virtual directories. I read that the way...
5
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.