SQLHelper connection life span

  • Thread starter Thread starter John H
  • Start date Start date
J

John H

I have a question about the life of the connection used by SQLHelper.
When I execute the lines below it looks as if it keeps the connection
to the database.

_sConnString = "Server=.;Database=tester;Integrated Security=SSPI;"
SqlHelper.ExecuteNonQuery(_sConnString, CommandType.Text, "select 1")

When I walk through the code and execute the lines above I can check
for the
connections in Query Analyzer using sp_who2 and I see a new SPID for
this process. I thought that the method was just going to open the
connection to execute the query and then close it's connection.

The problem I have is that later in the code when I open a connection
to the master database and try to drop database tester, I get the
message that the tester database is in use. I can still see the SPID
record for the connection caused by the lines above.

Is there a way to make sure the database is not connected so that I
can drop the database properly?

John H
 
John H said:
I have a question about the life of the connection used by SQLHelper.
When I execute the lines below it looks as if it keeps the connection
to the database.

_sConnString = "Server=.;Database=tester;Integrated Security=SSPI;"
SqlHelper.ExecuteNonQuery(_sConnString, CommandType.Text, "select 1")


Is there a way to make sure the database is not connected so that I
can drop the database properly?

John,

Instead of passing in the connection string, open the connection yourself and
close it when you want it closed...passing the connection object to the data
application block.

Mythran
 
Once I added pooling=false to the connection string the connection
worked as I expected and sp_who2 did not have a SPID for my program.

This works for when I explictly open a connection object and then
close it as well as for when I just pass the connection string to the
SQLHelper method.

Thanks,
John H
 
Back
Top