Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 ASP ADO Command Object Reuse??

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2005-02-09 : 21:39:39
Can an ADO command object be reused to call the same Stored Proc in ASP / ADO?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-02-09 : 22:19:20
Absolutely. You can even change the CommandText, CommandType, and the ActiveConnection on the same instance if you like.
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-02-09 : 22:59:30
OK.
	Set objCmd = CreateObject("ADODB.Command")
' Read the recordset of emails to be sent
With objCmd
.ActiveConnection = ConnString
.CommandType = adCmdStoredProc
.CommandText = "dbo.EM_SendEmailJob" 'Our Stored procedure
.Parameters.Append .CreateParameter ("RETURN_VALUE", adInteger, adParamReturnValue)
.Parameters.Append .CreateParameter ("@RecordCount", adInteger, adParamInput, , intMaxRecords) ' 0 = all records, N = Max recordset size
.Parameters.Append .CreateParameter ("@Message", adVarchar, adParamInput, 1000, strDisplayMessage) ' 0 = all records, N = Max recordset size
.Parameters.Append .CreateParameter ("@EPID", adInteger, adParamInputOutput, , 0) ' Set to zero to read the next recordset
Set objRS = .Execute 'Gets an ADO recordset of all the emails
End With


strMessage = "This is a new message for the second call"

			.Execute ,,adExecuteNoRecords ' Execute same command object with revised intEPID to record send duration statistics


Is anything else needed to load strMessage into @Message before the 2nd execution of objCmd?
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-02-09 : 23:08:48
Im not sure I understand your question SamC. You can reuse that command object as many times as needed. Once your done just set it to =Nothing. BTW, rather than sending 1000, you could send Len(strMessage) if you wanted to.

Jon



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-02-10 : 16:42:36
Once a command object has Parameters created... e.g.

.Parameters.Append .CreateParameter ("@Message", adVarchar, adParamInput, 1000, strDisplayMessage)

Those parameters remain created for subsequent executions of the command object. I'm not clear on whether these previously created .Parameters are "Updated" on each invocation of the command object or whether some kind of .Parameter.Update command must be invoked.

Never reused a command object before...
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-02-11 : 08:25:09
quote:
Originally posted by SamC

Once a command object has Parameters created... e.g.

.Parameters.Append .CreateParameter ("@Message", adVarchar, adParamInput, 1000, strDisplayMessage)

Those parameters remain created for subsequent executions of the command object.

The way to define an adParamInput parameter in subsequent executions of the command object is:

objCmd.Parameters("@Message").Value = strDisplayMessage

Go to Top of Page
   

- Advertisement -