Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Let sleeping SPIDS lie

Author  Topic 

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-24 : 14:13:01
A developer came over and asked me a couple of things

1. Can C# not cleanup SPIDs and just open new ones lieing around

2. Do a large number of spids, even if they are sleeping, cause performance issues?

3. What's the Max # of spids sql server can handle?

BOL ain't too helpful right now

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-24 : 15:21:16
it does clean up connections, but beacuse of the connection pooling you get sleeping spids.
if they keep piling up your iis will reset but that's probably a large number of spids that need to be left spleeping.
sql server supports a max of 32767 connections so that's not a problem.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-24 : 15:28:29
quote:
Originally posted by spirit1

it does clean up connections, but beacuse of the connection pooling you get sleeping spids.
if they keep piling up your iis will reset but that's probably a large number of spids that need to be left spleeping.
sql server supports a max of 32767 connections so that's not a problem.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out



Is that configurable in .NET..I mean do they set the connections

I see about 8 on my dev box



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-24 : 15:35:21
connection pooling? connection pooling is a good thing. don't turn it off.
if you really must the in .Net SqlConnection object add "Pooling=False;" to the connection string.

the thing with connection pooling is that even after you close the connection it keeps it open for a few seconds just in case and then it closes it.


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-24 : 15:42:20
From what I understand connection pooling leaves the connections open and hangs on to them until it needs it again

But is the number of connections configurable?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-24 : 15:50:20
"Min Pool Size" and "Max Pool Size" in the connection string

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-24 : 16:57:08
They don't let me do much .net where I am now but I seem to recall that once you have a reference to a sqlConnection you can view and set all those nice properties. It doesn't have to be defined by the user in the connection string itself. ie: cn.pooling=false; etc...

Be One with the Optimizer
TG
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-28 : 08:19:05
I gotta get a book

Once a connection string is made, is it persitant?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-28 : 08:23:35
define "persistant".

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-28 : 08:28:33
Mladen, would you agree with the following statement?
I think the practice is to Close the connection as soon as you've used it, but the reference to the (closed) connection, as well as whatever connection properties you've set, persists for the scope of the variable.

Be One with the Optimizer
TG
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-28 : 08:34:37
quote:
Originally posted by spirit1

define "persistant".

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out



OK, If I were to spell it correctly

http://www.google.com/search?hl=en&rlz=1G1GGLQ_ENUS256&defl=en&q=define:persistent&sa=X&oi=glossary_definition&ct=title



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-28 : 08:39:54
no i don't care about the spelling brett

i mean what do you mean by persistent? it would persist how?


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-28 : 08:42:48
quote:
Originally posted by TG

Mladen, would you agree with the following statement?
I think the practice is to Close the connection as soon as you've used it, but the reference to the (closed) connection, as well as whatever connection properties you've set, persists for the scope of the variable.

Be One with the Optimizer
TG



scope of what variable?

when you close the connection in your code the connection state is changed to closed. because of the connection pooling the connection itself stays open for a few seconds then goes back to the pool. it's not really disposed and permanently destroyed. they do get destroeds after a while of unuse. i don't know how long "a while" is though.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-28 : 08:51:39
ok, here's a stupid basic question

Is a SPID the same thing as a connection?

I didn't think so, but I see all these sleeping spids out there



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-28 : 09:05:20
in ss2k:
A spid is an internal id that Sql Server assigns to a connection to the database server.

in ss2k5 it's a bit more complex because of MARS.


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-28 : 09:28:37
MARS?

What about Venus?

I am so lost



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-28 : 09:30:54
MARS = Multiple Active Result Sets
http://www.sqlteam.com/article/multiple-active-result-sets-mars
http://www.sqlteam.com/article/multiple-active-result-sets-mars-transactions-and-debugging

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-28 : 10:19:19
quote:
Originally posted by spirit1

quote:
Originally posted by TG

Mladen, would you agree with the following statement?
I think the practice is to Close the connection as soon as you've used it, but the reference to the (closed) connection, as well as whatever connection properties you've set, persists for the scope of the variable.

Be One with the Optimizer
TG



scope of what variable?

when you close the connection in your code the connection state is changed to closed. because of the connection pooling the connection itself stays open for a few seconds then goes back to the pool. it's not really disposed and permanently destroyed. they do get destroeds after a while of unuse. i don't know how long "a while" is though.



I interpereted Brett's original question as from the perspective of a .net application, so my term "variable" was referring to the reference to a "System.Data.SqlClient.sqlConnection" object. I have had some very confusing conversations when discussing "sql connections". I would say that a .net connection object can manage many sql connections and the .net developer is unaware of the number and state of those actual sql server sessions that can exist by vitue of a .net connection object.

Brett, I have no idea of your .net experience. You may be way past my modest knowledge so please forgive me if that's true but would it help to see some .net code samples?

Be One with the Optimizer
TG
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-28 : 10:24:54
quote:
[i]Originally posted by TGBrett, I have no idea of your .net experience. You may be way past my modest knowledge so please forgive me if that's true but would it help to see some .net code samples?



Zero

Sorry, I guess I need to dive into the pool



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-28 : 11:00:50
quote:
Sorry, I guess I need to dive into the pool

groan - just make sure you haven't eaten in the past 2 hours...

At the risk of laughter from all the real .net folks out there:

This is a "class" that I wrote about 4 years ago as part of a little sql Load Testing application. It is not a complete solution so this won't run on its own, but at least you can see a little .net code The idea of the app is that there is a txt file that contains a list of typical SP calls including parameters. The LoadTester creates <number> of Users. The number of users ramps up to <number> and then runs for <time> then removes the users one at a time until they are all gone. Each user cycles through all the commands in the text file for a configurable number of times with a configurable wait time between each call.

There is an accomying sql script which turns on and saves results of a sql trace running at the same time as this test so I could analyze duration, reads etc under varying loads.

This "SPCallerInstance" class represents one call from one user instance. Notice I am creating a new sqlConnection object for each call but I have also explicitly set the connection string to allow pooling. I think .net managed a pool of connections even though this connection OBJECT dies between calls. I'm not sure though, Mladen probably knows .

/// <summary>
/// SPCallerInstance represents a user instance. It will loop through
/// the sp call script, exec the current call after the specified delay.
/// Log call statistics, track call count
/// </summary>
public class SPCallerInstance
{
SqlCommand _cmd;
SqlDataReader _dr;
SqlConnection _cn;

try
{
_cn = new SqlConnection();
_cn.ConnectionString =
"Application Name=" + TestController._appname +
";Connection Timeout=35" +
";Server=" + TestController._dbserver +
";Database=" + TestController._db +
";Encrypt=false" +
";Integrated Security=" + TestController._integratedsecurity +
";Persist Security Info=false" +
";Connection Lifetime=0" +
";Connection Reset=false" +
";Enlist=false" +
";Max Pool Size=100" +
";Pooling=true";

if (TestController._integratedsecurity == "false")
{
_cn.ConnectionString = _cn.ConnectionString +
";User ID=" + TestController._dbaccountname +
";Password=" + TestController._dbaccountpwd;
}

_cmd = new SqlCommand();
_cmd.CommandTimeout = 30;
_cmd.CommandType = System.Data.CommandType.Text;
_cmd.Connection = _cn;
_cmd.CommandText = TestController._alSPCalls[_cmdIndex].ToString();

//------------------------------------------
//exec the command and count rows and the call duration

_cmd.Connection.Open();
_dr = _cmd.ExecuteReader();

if(_dr != null)
{
while(_dr.Read())
_rowcount ++;
_dr.Close();
}
if(_cmd.Connection.State != ConnectionState.Closed)
_cmd.Connection.Close();
//------------------------------------------
}
catch(Exception ex)
{
if(! _dr.IsClosed)
_dr.Close();

if(_cn.State != ConnectionState.Closed)
_cn.Close();

this.KillMe();

LogError(ex);
}
}


Be One with the Optimizer
TG
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-01-28 : 11:07:13
connection object is disposed but the connection remains in the connection pool and is fetched from it on the next reuse.
the connection is removed from connection pool after some period time.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out
Go to Top of Page
    Next Page

- Advertisement -