[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


BeginExecuteNonQuery - call a procedure without waiting for it to complete

Posted on 2014-07-16
Medium Priority
Last Modified: 2014-07-18
I am running a query in sql that takes many minutes to execute. I want to call the query from my website and the user should not have to wait for it to finish, i.e. as soon as he gives the command to execute the query he should be able to go to do somehting else on my website. I am trying to use BeginExecuteNonQuery.
With following code I do not call the pocedure. Do you know what I am doing wrong?

public void test_T1_Insert(string t1)
        SqlCommand command = new SqlCommand("test_T1_Insert", connection);
        command.CommandType = CommandType.StoredProcedure;

        command.Parameters.Add("@T1", SqlDbType.VarChar);
        command.Parameters[0].Value = t1;
Question by:johnson1
LVL 21

Assisted Solution

by:Randy Poole
Randy Poole earned 400 total points
ID: 40199400
Unfortunately the page must stay open until the query is completed.  You could utilize html frame with a hidden frame that can spawn iframes which runs these types of queries or you can utilize a run table with the SQL Server Agent which can then query the table and run the needed operation.  You can find more on this command and how it works here:

LVL 70

Accepted Solution

Scott Pletcher earned 1600 total points
ID: 40199920
You could also create a job to run the query, then start the job.  When you run sp_start_job, SQL just starts the job and returns immediately to the caller.  You can set the job to delete itself, to prevent jobs from building up in SQL Agent.

Author Closing Comment

ID: 40204197
Thank you.

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question