Unix Technical Forum

SQL Connections with VB.NET

This is a discussion on SQL Connections with VB.NET within the SQL Server forums, part of the Microsoft SQL Server category; --> As most of you are aware, when you close a VB.NET connectrion to a SQL server, the connection doesn't ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 08:45 AM
Joe Cool
 
Posts: n/a
Default 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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 08:45 AM
Marina
 
Posts: n/a
Default Re: SQL Connections with VB.NET

This is called connection pooling. It is a good thing, why would you want to
get rid of it?

"Joe Cool" <joecool@home.net> wrote in message
news:qjqr911o1pun4psdtkn7j76ncs0a3n5j4b@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?
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 08:45 AM
Daniel vom Saal
 
Posts: n/a
Default Re: SQL Connections with VB.NET

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" <joecool@home.net> wrote in message
news:qjqr911o1pun4psdtkn7j76ncs0a3n5j4b@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?
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 08:45 AM
Paul Clement
 
Posts: n/a
Default Re: SQL Connections with VB.NET

On Wed, 01 Jun 2005 17:07:39 GMT, Joe Cool <joecool@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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 08:45 AM
Joe Cool
 
Posts: n/a
Default Re: SQL Connections with VB.NET

On Wed, 1 Jun 2005 13:49:16 -0400, "Marina" <someone@nospam.com>
wrote:

>This is called connection pooling. It is a good thing, why would you want to
>get rid of it?
>
>"Joe Cool" <joecool@home.net> wrote in message
>news:qjqr911o1pun4psdtkn7j76ncs0a3n5j4b@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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-29-2008, 08:46 AM
Erland Sommarskog
 
Posts: n/a
Default Re: SQL Connections with VB.NET

Joe Cool (joecool@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, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-29-2008, 08:46 AM
MrDom
 
Posts: n/a
Default Re: SQL Connections with VB.NET

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-29-2008, 08:46 AM
Greg D. Moore \(Strider\)
 
Posts: n/a
Default Re: SQL Connections with VB.NET


"Joe Cool" <joecool@home.net> wrote in message
news:a06s91lb492bkus82046v2u3u4s4fmko62@4ax.com...
> On Wed, 1 Jun 2005 13:49:16 -0400, "Marina" <someone@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.


>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-29-2008, 08:47 AM
Joe Cool
 
Posts: n/a
Default Re: SQL Connections with VB.NET

On Wed, 1 Jun 2005 21:47:33 +0000 (UTC), Erland Sommarskog
<esquel@sommarskog.se> wrote:

>Joe Cool (joecool@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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-29-2008, 08:47 AM
Joe Cool
 
Posts: n/a
Default Re: SQL Connections with VB.NET

On Thu, 02 Jun 2005 01:25:56 GMT, "Greg D. Moore \(Strider\)"
<mooregr_deleteth1s@greenms.com> wrote:

>
>"Joe Cool" <joecool@home.net> wrote in message
>news:a06s91lb492bkus82046v2u3u4s4fmko62@4ax.com.. .
>> On Wed, 1 Jun 2005 13:49:16 -0400, "Marina" <someone@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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:38 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com