We help IT Professionals succeed at work.
Get Started

Run SQL Store Procedure using Excel VBA

778 Views
Last Modified: 2012-05-12
Hi there,

I need to run a store procedure or SQL job from within excel.
I have a storeprocedure which dies some extensive data manipulation and creates a summarized table.

I then use this table to run queries with excel. (No problem ith this.

I'd like to be able to run the stored procedure in vbas priot to doing my query refresh.

I've looked on varios discusions in ~EE and have tried a few.

The last one suggested putting my sp in a job and then running the job.

I'm obviously doing something wrong but can someone please help

Here's my vba code to run the SQL job


Dim c As ADODB.Connection
Set c = New ADODB.Connection
'c.Open "Provider=SQLOLEDB.1;User ID=sa;Initial Catalog=EB_Production;Data Source=EBDBSQL\EBSQL;PWD=3ntri3$$"
c.Open "DRIVER=SQL Server;SERVER=EBDBSQL\EBSQL;UID=sa;PWD=3ntri3$$;APP=Microsoft Office 2003;WSID=EBDBSQL;DATABASE=EB_Production"
c.Execute "exec msdb.dbo.sp_start_job @job_name = 'Packing_Invoicing' "
c.Close
Set c = Nothing


also here's an example connection string from one of the queries. Don't know if that's relevant

DRIVER=SQL Server;SERVER=EBDBSQL\EBSQL;UID=sa;APP=Microsoft Office 2003;WSID=EBDBSQL;DATABASE=EB_Production
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE