Help With Code

M

MSNews

Dear All

I am using Access 2000 with SQL 2000 and i am trying to run a stored
procedure from Access and i am not using a data project.

When i run this code i get an error :

Method Execute of object _command failed

Here is my code:

Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset

' Create connection and command objects
Set cn = New ADODB.Connection
Set cmd = New ADODB.Command
Set rs = New ADODB.Recordset

' Set connection properties and open
cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=Rugby; " & _
"Data Source=PROZONEDB"
cn.CursorLocation = adUseClient
cn.Open

' Set command properties
With cmd
Set .ActiveConnection = cn
.CommandText = "sp_Append_Fitness"
.CommandType = adCmdStoredProc

End With

' Execute the command
Set rs = cmd.Execute


Many Thanks

Ash
 
J

JohnFol

Might be worth checking the connection state is Open. Also the connection
object holds an errors collection. Try doing :
? cn.errors.count

and then for each one
? cn.error(1).Description
? cn.error(2).Description

and so on. At least it will give you some more info to go on.
 
A

Alick [MSFT]

Hi Mike,

We can try the connection string as follows:

cn.Provider = "SQLOLEDB"
cn.ConnectionString = "server=sqlservername;database=Northwind;uid=sa;pwd=;"
cn.CursorLocation = adUseClient
cn.Open


Sincerely,

Alick Ye, MCSD
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.




--------------------
| From: "MSNews" <1>
| Subject: Help With Code
| X-Tomcat-NG: microsoft.public.access.formscoding
|
| Dear All
|
| I am using Access 2000 with SQL 2000 and i am trying to run a stored
| procedure from Access and i am not using a data project.
|
| When i run this code i get an error :
|
| Method Execute of object _command failed
|
| Here is my code:
|
| Dim cn As ADODB.Connection
| Dim cmd As ADODB.Command
| Dim rs As ADODB.Recordset
|
| ' Create connection and command objects
| Set cn = New ADODB.Connection
| Set cmd = New ADODB.Command
| Set rs = New ADODB.Recordset
|
| ' Set connection properties and open
| cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security
Info=False;User
| ID=sa;Initial Catalog=Rugby; " & _
| "Data Source=PROZONEDB"
| cn.CursorLocation = adUseClient
| cn.Open
|
| ' Set command properties
| With cmd
| Set .ActiveConnection = cn
| .CommandText = "sp_Append_Fitness"
| .CommandType = adCmdStoredProc
|
| End With
|
| ' Execute the command
| Set rs = cmd.Execute
|
|
| Many Thanks
|
| Ash
|
|
|
 

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