Re: using(SqlConnection = ... ) ?

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 05/27/04


Date: Thu, 27 May 2004 13:34:42 +0100

sevenfifteen <anonymous@discussions.microsoft.com> wrote:
> If you call Close() on an SqlConnection, then that makes it disappear from sp_who2
> or Enterprise Manager. i.e. you're actually telling SQL server that
> you don't want to use that connection any more.
> If you let a using block expire, it doesn't.
> Damn.

It certainly doesn't log out the connection - or at least, it didn't
when I last tried it, looking at SQL Server Profiler. I suggest you use
the profiler to see what happens - I've got a test program in the
.adonet newsgroup from about a week ago asking about the same question.

In fact, I've just tried executing sp_who2 myself with my test program,
after opening and closing a connection 3 times - and I see two sleeping
connections. It's only after the process exits that the connections
drop.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Error "SQL Server does not allow remote connections"
    ... The application could not connect to the sql server db. ... network is blocking the connection. ... SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 ... integratedSecurity, SqlConnection owningObject) +737554 ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Connection from remote computer to network SQL Server
    ... There is no firewall on the W2K machine acting as the SQL server. ... I tried making the SQL machine a "trusted" on the router. ... connection works. ... To find the IP address of your computer inside the network, ...
    (microsoft.public.access.adp.sqlserver)
  • ADO.net Orcas Samples Install Problem
    ... An error has occurred while establishing a connection to the server. ... When connecting to SQL Server 2005, this failure may be caused by the ... SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, ... or am I better off with a full SQL Server install. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: OpenDataSource SQL Server xpress problem
    ... I tried your suggestions with some success. ... I tried setting up the .odc file through the Word Mail Merge wizard as ... If I work through the dialog to connect and then click the 'Test Connection' ... but I suspect it's because until recently most SQL Server ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Exception trying to import data from Excel .
    ... An attempt to install Microsoft SQL Server 2005 this week has not gone ... The connection type "EXCEL" specified for connection manager ... to create a connection manager for an unknown connection type. ...
    (microsoft.public.sqlserver.tools)