executing stored proc from Excel

D

doofy

I'm trying to execute a stored proc from within Excel. The id and
password work for external data queries to this same database.

Here's the code:


Dim cnn As ADODB.Connection
Dim Cmd As ADODB.Command


Set cnn = New ADODB.Connection
cnn.Open
"provider=SQLoledb;SERVER=192.168.xx.yy;UID=xx;PWD=xxxxxxxx;DATABASE=YYYYYYYY"

Debug.Print cnn.State
Debug.Print cnn.ConnectionString

Set Cmd = New ADODB.Command

Set Cmd.ActiveConnection = cnn

Cmd.CommandText = "execute rptRRTP_SCORECARD"
Cmd.CommandType = adCmdStoredProc
Cmd.Execute


The Debug.print lines are for debugging. Seems to bring back a properly
formatted connection string.

It blows up on that last line. This is the error I get:


Syntax error or access violation


What should I be looking at? I can log in with the id/pw I'm trying to use.
 
D

doofy

urkec said:
Try setting CommandText to procedure name:

Cmd.CommandText = "rptRRTP_SCORECARD"

I fixed it. I had to set the CommandType from adCmdStoredProc to
adCmdText (or something like that), AND I had to do what you just said.

Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top