Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Server - Execute a store procedure asynchronously from Excel

Posted on 2013-10-23
8
Medium Priority
?
1,054 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 2000 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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 2000 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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

688 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