SQL Server - Execute SQL Server store procedure from Excel

Hi,

Could you please let me know why my code below isn't working?

        Set cmd = New ADODB.Command
        cmd.ActiveConnection = Cn
        cmd.CommandText = "Exec TRP.M_Par_update_process"
        'cmd.CommandTimeout = 1200               ' 20 minutes
        cmd.CommandType = adCmdStoredProc
        cmd.Execute , , adAsyncExecute
        MsgBox ("Loaded & Processed!")

When a button in Excel is clicked, I want it to execute a store procedure name "TRP.M_Par_update_process" in the SQL Server without having to wait in Excel until the procedure is completely done.
HNA071252Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nutschCommented:
If you use the command type for stored proc, just enter the name of the stored proc, not the command text, i.e. replace
 cmd.CommandText = "Exec TRP.M_Par_update_process"

Open in new window

by
 cmd.CommandText = "TRP.M_Par_update_process"

Open in new window


Thomas
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leonstrykerCommented:
Of course, you can always just use the Connection object to run a store procedure

Cn.Execute "Exec TRP.M_Par_update_process"

Open in new window

0
HNA071252Author Commented:
When I executed the store procedure using adAsyncExecute, how do I know when it's finish running? From the SQL Server Management Studio window, how do I check what are the procedures currently running?
0
SharathData EngineerCommented:
You can find out currently running statements with this query. You can embed this into your VBA code and check if the stored proc is running.
SELECT r.*,t.text FROM sys.dm_exec_requests r cross apply sys.dm_exec_sql_text(r.sql_handle) t
WHERE r.status IN (N'Suspended',N'Running',N'Runnable',N'Pending')

Open in new window


http://www.sqlservercentral.com/Forums/Topic813548-146-1.aspx
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Hi all

I know this question has already been answered, but if it helps I finished an article on how to build an Excel front-end, SQL Server Stored Procedure back-end that allows users to enter cell-based parameters:

Microsoft Excel & SQL Server:  Self service BI to give users the data they want
If you like what you see, please click the 'Yes' button next to 'Was this article helpful?', and provide some feedback.

Thanks in advance.
Jim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.