recordset via cmd object

S

smk23

I would like to return a recordset using a command object:

Set mCmd = New ADODB.Command
With mCmd
.ActiveConnection = mConn
.CommandText = brSelectCommandText
.CommandType = adcmdStoredProc
Set mrst = New ADODB.Recordset
Set mrst = .Execute

When I run this, it returns the error "syntax error or access violation" on
the Execute line. The connection is checked prior to this and confirmed open.
When I run the text in .CommandText from Query Analyzer (SQL server 2000),
there is no problem (returns the recordset). WHat can I do now to find the
error?

Sam
 
D

Dirk Goldgar

smk23 said:
I would like to return a recordset using a command object:

Set mCmd = New ADODB.Command
With mCmd
.ActiveConnection = mConn
.CommandText = brSelectCommandText
.CommandType = adcmdStoredProc
Set mrst = New ADODB.Recordset
Set mrst = .Execute

When I run this, it returns the error "syntax error or access violation"
on
the Execute line. The connection is checked prior to this and confirmed
open.
When I run the text in .CommandText from Query Analyzer (SQL server 2000),
there is no problem (returns the recordset). WHat can I do now to find the
error?


From what I can see, that code ought to work, provided that you have
properly declared the objects and previously opened the connection mConn --
though it doesn't make sense to set mrst to a new ADODB recordset, and then
immediately discard that recordset for the one returned by the Execute
method. You don't need the line, "Set mrst = New ADODB.Recordset".

Is that a direct copy/paste from your module, though? I ask because the
constant "adcmdStoredProc" isn't capitalized correctly, suggesting the
possibility that you may have redefined it.

If that's not the problem, can you verify that brSelectCommandText is the
name of a stored procedure in the connected database?
 

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