Solved

SQL Server - Execute a store procedure asynchronously from Excel

Posted on 2013-10-23
8
1,040 Views
Last Modified: 2014-03-12
Set cmd = New ADODB.Command
        cmd.ActiveConnection = Cn
       
        cmd.CommandText = "TRP.FFS_Contracts_process_v1"
        cmd.CommandType = adCmdStoredProc
        cmd.Execute , , adAsyncExecute
             
        cmd.CommandText = "Update TRP.Param set F_Proj_type = 'P'"
        cmd.CommandType = adCmdText
        cmd.Execute
       
        cmd.CommandText = "TRP.sp_FFS_Projection"
        cmd.CommandType = adCmdStoredProc
        cmd.Execute , , adAsyncExecute

Could you please let me know why I'm getting an error message on this line and how to fix it?
        cmd.CommandText = "Update TRP.Param set F_Proj_type = 'P'"

Error message says "Operation cannot be performed while executing asynchronously"
0
Comment
Question by:HNA071252
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 500 total points
ID: 39595963
a single connection cannot execute multiple command at the same time.

why don't you just send the 3 queries at the same time?

        cmd.CommandText = "exec TRP.FFS_Contracts_process_v1 " +
                                              "Update TRP.Param set F_Proj_type = 'P' " +
                                              "exec TRP.sp_FFS_Projection "
        cmd.CommandType = adCmdText
        cmd.Execute , , adAsyncExecute
0
 

Author Comment

by:HNA071252
ID: 39601642
with combining the 3 queries in one command, is it execute one after another or simultaneously? because I would need the first one done, before the 2nd, then the 3rd.
0
 

Author Comment

by:HNA071252
ID: 39711941
Would anyone please help me with my question above?
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39711986
what have you done of the 2 comments?
0
 

Author Comment

by:HNA071252
ID: 39712078
You asked me to combine the three queries in one command:

        cmd.CommandText = "exec TRP.FFS_Contracts_process_v1 " +
                                              "Update TRP.Param set F_Proj_type = 'P' " +
                                              "exec TRP.sp_FFS_Projection "
        cmd.CommandType = adCmdText
        cmd.Execute , , adAsyncExecute

and I asked if is it execute one after another or simultaneously? Although I didn't get Error message says "Operation cannot be performed while executing asynchronously", but it didn't execute all three commands, it didn't continue on executing it in the Server but it stops when I closed Excel.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 39712131
since it is a single command, the 3 statements will run one after the other.

try removing your adAsyncExecute
0
 

Author Comment

by:HNA071252
ID: 39712144
If I remove adAsyncExecute, then the command cmd.Execute is hanging in Excel until it finish which can be as long as an hour and I don't want to wait in Excel, I wanted to continue executing in the Server even when I'm done with Excel but I couldn't figure how to make it work,
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 39712179
the execution stops because the connection is closed. so you need to run the command from a different context. one way of achieving this is to schedule your commands.

check the sample at http://stackoverflow.com/questions/287060/scheduled-run-of-stored-procedure-on-sql-server
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

636 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