Re: Closing a connection BEFORe command execution has completed



Actually, closing the connection with Connection.Close does not close the connection--it simply releases it back to the pool so the engine will continue to fill the cache--but it's not that large so the operation might simply hang resources on the server until the connection is reused.

The problem is, since all of the (normal) Execute methods are synchronous, there is no way to interrupt the query or action command process. The solution you seek can only be accomplished by running the query asynchronously. While waiting for the query to complete you can execute Command.Cancel. Because of the way TDS and SQL Server responds to cancel requests your operation might not be immediately "stoppable"--SQL Server might have some cleanup to do before releasing control and resources.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
-----------------------------------------------------------------------------------------------------------------------
"Amir Tohidi" <AmirTohidi@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:4C0F7B92-18AC-4D6F-A7EB-F19FEBCA99D0@xxxxxxxxxxxxxxxx
Hi

What happens in the above scenario? Does the query still continue executing
on the Databas server or is it immmediately terminated and resources released
(including locks).

If this is not recommended, then what is the recommended approach for
terminating command's execution.

Thanks in advance

.



Relevant Pages

  • Re: Query from ms sql server question
    ... For example, in my worksheet, there a cell which user will enter the production number and macro will perform an automatic connection to sql server and query the table base on the production number and retrieve the data base on the production alone and place it on the excel sheet. ...
    (microsoft.public.excel.programming)
  • Re: Interesting Problem regarding Parameters
    ... > reasons, however we have one slight problem we would very much like to ... > logging to our database connection object. ... > query that was actually executed on the server, what I mean by that is: ... > //Set the query with parmater then execute reader ...
    (microsoft.public.dotnet.framework.adonet)
  • Interesting Problem regarding Parameters
    ... My company is currently migrating to .Net from PHP for a number of reasons, ... database connection object. ... What our current database class will do (after executing the query) is logg ... //Set the query with parmater then execute reader ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Problem with the Legacy ASP files and the Sql Server Express
    ... It looks like it is not going to be an easy job getting it to work on the SQL Server 2005 and Express:(. ... 'Then you can execute the command and then retrieve the ID ... I am 100% sure this code works against any version of SQL Server, as long as the connection is OK and the SP has two parameters @varCompany as Input and @Return_Value as Output. ... I do not think your problem is due to difference of SQL Server2000 and SQL Server2005, unless your stored procedure has some thing that only works in SQL Server2000, not SQL Server 2005. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: SQL Query Performance
    ... Execute the query and see which is faster. ... I support the Professional Association of SQL Server and it's community of SQL Server professionals. ... > I want to select Fleet_Id and Fleet_Name from fleet table> Where the current user has privilege. ...
    (microsoft.public.sqlserver.programming)