6

Related: How can you cancel a SQL Server execution process programmatically

I have created an application (Windows, WPF) which is basically a viewer for data in a database (Sql Server). The application has NO editing functionality.

The application provides the ability to search for records based upon input from the user. For the most part, the rows are searched by a key column and run pretty fast. But one column in the table is a large text field and I want to provide the ability to search for rows based on the content of this field. Because of this, the resulting sql query could take some time to complete. I want to provide a Stop button so that the user can abort the search, if desired. The link I placed above uses the Kill command to kill a spid in Sql server, but I'm not sure how this would work in my situation since I am using the Entity Framework (4.1)

For example, suppose a have a query similar to this:

var docs = from document in context.Documents
           join header in context.Headers
           on document.DocumentID equals header.HeaderID into headerGroup
           from subdoc in headerGroup.DefaultIfEmpty()
           where document.LargeTextColumn.Contains("search term")
           select (...)

foreach (var item in docs)
{
    //Do something with item here
}

Since the query doesn't actually happen until I iterate through it with the foreach statement, how can I provide the user with a "Stop Query" button? This is similar to the stop button in Sql Server Management Studio.

Is this possible?

Community
  • 1
  • 1
Chris Dunaway
  • 10,974
  • 4
  • 36
  • 48

0 Answers0