Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have written code to run a set of threads that works on data from sql server.

After calling Start and i have called the join.

But after processing still i am able to view the sql server instance running in database.

What should i do to kill the threads complete and end the sql server instance too.

thanks in advance!

Regards
Govardhan
Posted
Comments
nishantcomp2512 10-Nov-11 6:55am    
have you use property of thread "isbackground=true"?
Rob Philpott 10-Nov-11 9:26am    
Please clarify what you mean by 'But after processing still i am able to view the sql server instance running in database.'
govardhan4u 11-Nov-11 1:50am    
No i have not used isbackground=true.

"But after processing still i am able to view the sql server instance running in database" by this statement I mean is when I check the spids running in the database I able to see the spids of the thread still running even after the thread is abort from the dot net side.

close the connection properly..

1) call the Close() method of Connection
or
2) use the 'using' keyword like using(Connection con)
{ ... }
or
3) check the implecations for AutoClose
http://stackoverflow.com/questions/1275079/ado-net-connection-pooling-and-implications-for-autoclose-true[^]
 
Share this answer
 
Comments
govardhan4u 10-Nov-11 7:10am    
i have keep the close connection command in every function finally block. any other cases?
For killing thread you can call the Thread.Abort method like the following:
myThread.Abort();

For closing the SQL connection you can call the SqlConnection.Close method or, wrap your code with a using block, like the following:
C#
string connectionString = "Your connection string";
using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();

    // ...
}

 
Share this answer
 
Comments
govardhan4u 10-Nov-11 7:13am    
I have close the connection in the finally block.
Well, if I understand you correctly, you don't kill the SQL Server Instance. Its running out of process as a service, you merely disconnect from it.
 
Share this answer
 
Comments
govardhan4u 10-Nov-11 8:59am    
yes it is called as a service
govardhan4u 11-Nov-11 1:51am    
Hi Philpott,
can you help me out in this issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900