January 13, 2004 at 12:21 pm
I am trying to create a table and then create a stored procedure. I have the sql statements in separate strings. I use the same SQLCommand to execute both strings. Everything gets created correctly BUT when i try to drop the database, I get an error stating that the database cannot be dropped because it is in use. If I shut down my application, I then can drop the database. Why is this?
Here is the code snippet
try
{
//create connection
conn =
new SqlConnection(connectionString);
//Open the connection
conn.Open();
//create Command
cmd =
new SqlCommand(sql, conn);
//execute cmd
cmd.ExecuteNonQuery();
//execute the second command
cmd=
new SqlCommand(CreateStoredProcedure(), conn);
cmd.ExecuteNonQuery();
}
catch(SqlException ae)
{
throw ae;
}
finally
{
if(conn != null)
{
conn.Close();
}
}
PLEASE HELP!!!
January 13, 2004 at 1:51 pm
This is a feature of connection pooling. Whenever you create a SqlConnection, it checks the pool and if there is another connection w/ the same connection string, it uses the pre-existing connection. The drawback to this is that when you close the connection, the pool actually keeps it open in case it is used again. It remains open as long as the process is running. To avoid this, you can disable pooling by adding "pooling=false" to your SQL connection string. There are performance issues if you do not use pooling, so be aware of these. If you are only using the one connection, there should be no problem.
January 15, 2004 at 10:52 am
I tried adding pooling=false to the connection string BUT I am still experiencing the same problem. Any other suggestions?
Thanks!
January 15, 2004 at 11:01 am
DISREGARD THE LAST POST, for some reason the pooling=false is working now.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply