Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a stored proc from VB

Status
Not open for further replies.

tsherfy

Programmer
Dec 23, 2000
20
US
We have the following stored procedure that runs fine in SQL Server 2000 Query Analyzer.

/*
** Retrieve next available Request ID
*/
CREATE procedure dbo.sp_GetRequestID2

@output int OUTPUT

as

/* begin transaction */

select @output = (select NextID from RequestID)

update dbo.RequestID set NextID = (NextID + 1)

/* commit */

Return 99
GO

However, when calling the proc from VB with the code below, we are not getting any results. Any ideas?

Dim strTest As String
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim param1 As Parameter
Dim param2 As Parameter

Set cmd = New ADODB.Command

cmd.ActiveConnection = "Provider=SQLOLEDB.1;Password=mypassword;Persist Security Info=True;User ID=myuser;Initial Catalog=HVDB;Data Source=TESTSERVER"

cmd.CommandType = adCmdStoredProc
cmd.CommandText = "sp_GetRequestID2"

' Set up a return parameter.
Set param1 = cmd.CreateParameter("Return", adInteger, adParamReturnValue)
cmd.Parameters.Append param1

' Set up an output parameter.
Set param2 = cmd.CreateParameter("Output", adInteger, adParamOutput)
cmd.Parameters.Append param2

Set rs = cmd.Execute

strTest = cmd(1)

Thanks!
 
Are you getting any results? How about return code.

debug.print cmd(0)

Do you know that it is executing the SP.

Normally, you should have dbo on the SP unless you are logged in as the owner or sa.


cmd.CommandText = "dbo.sp_GetRequestID2"
 

Use SET NOCOUNT ON in the beginning of SQL Statements after the keyword AS and use SET instead of Select.

CREATE procedure dbo.sp_GetRequestID2

@output int OUTPUT

as

SET NOCOUNT ON

/* begin transaction */

SET @output = (select NextID from RequestID)

update dbo.RequestID set NextID = (NextID + 1)

/* commit */

Return 99
GO


Muhammad Essa Mughal
Software Engineer
essamughal@yahoo.com
 
Thanks to all who responded. We were able to correct our mistakes based on Muhammed's post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top