I am trying to return a recordset from a SQL SERVER 2000 stored procedure using VB6 and ADO.
The Stored Procedure That I am accessing works fine from the Query analyzer, but I can't seem to execute it through code.
The Error that is returned is:
-2147217904
Please help...This is driving me crazy!!!
Here is the Stored procedure:
CREATE PROCEDURE [GetPetPickups2]
@cStartDate varchar(40),
@cEndDate varchar(40)
AS
SET NOCOUNT ON
DECLARE @Startdate DATETIME
set @Startdate=CONVERT(datetime, @cStartDate)
DECLARE @EndDate DATETIME
set @EndDate=CONVERT(datetime, @cEndDate)
exec('SELECT * FROM tblPetInfo
WHERE PickupDate BETWEEN "' + @StartDate + '" and "' + @EndDate + '"')
GO
Here is the VB Code:
Public Function GetPetPickups(ByVal sServerName As String, ByVal sDatabaseName As String,ByVal sDatabasePassword As String, ByVal sSqlUserID As String, ByVal sStartdate As String, ByVal sEndDate As String) As adodb.Recordset
On Error GoTo EH
Dim objConn As New adodb.Connection
Dim objCommand As New adodb.Command
Dim sStoredProcedureName As String
Dim aParams(0 To 1) As Variant
Let aParams(0) = sStartdate
Let aParams(1) = sEndDate
Let sStoredProcedureName = "GetPetPickups2"
With objConn
.ConnectionString = "Provider=SQLOLEDB;Persist Security Info=True;User ID=" & sSqlUserID & ";Initial Catalog=" & sDatabaseName & ";Data Source=" & sServerName & ";Network Library=dbmssocn" & ";Password=" & sDatabasePassword
.Open
End With
With objCommand
.CommandType = adCmdStoredProc
.CommandText = sStoredProcedureName
.ActiveConnection = objConn
End With
Set GetPetPickups = New adodb.Recordset
Set GetPetPickups = objCommand.Execute
Set objCommand = Nothing
objConn.Close
Set objConn = Nothing
EH:
Let lErrorCode = Err.Number
End Function
Thanks in advance
--Brian
Blauther@SoundSoftware.cc
The Stored Procedure That I am accessing works fine from the Query analyzer, but I can't seem to execute it through code.
The Error that is returned is:
-2147217904
Please help...This is driving me crazy!!!
Here is the Stored procedure:
CREATE PROCEDURE [GetPetPickups2]
@cStartDate varchar(40),
@cEndDate varchar(40)
AS
SET NOCOUNT ON
DECLARE @Startdate DATETIME
set @Startdate=CONVERT(datetime, @cStartDate)
DECLARE @EndDate DATETIME
set @EndDate=CONVERT(datetime, @cEndDate)
exec('SELECT * FROM tblPetInfo
WHERE PickupDate BETWEEN "' + @StartDate + '" and "' + @EndDate + '"')
GO
Here is the VB Code:
Public Function GetPetPickups(ByVal sServerName As String, ByVal sDatabaseName As String,ByVal sDatabasePassword As String, ByVal sSqlUserID As String, ByVal sStartdate As String, ByVal sEndDate As String) As adodb.Recordset
On Error GoTo EH
Dim objConn As New adodb.Connection
Dim objCommand As New adodb.Command
Dim sStoredProcedureName As String
Dim aParams(0 To 1) As Variant
Let aParams(0) = sStartdate
Let aParams(1) = sEndDate
Let sStoredProcedureName = "GetPetPickups2"
With objConn
.ConnectionString = "Provider=SQLOLEDB;Persist Security Info=True;User ID=" & sSqlUserID & ";Initial Catalog=" & sDatabaseName & ";Data Source=" & sServerName & ";Network Library=dbmssocn" & ";Password=" & sDatabasePassword
.Open
End With
With objCommand
.CommandType = adCmdStoredProc
.CommandText = sStoredProcedureName
.ActiveConnection = objConn
End With
Set GetPetPickups = New adodb.Recordset
Set GetPetPickups = objCommand.Execute
Set objCommand = Nothing
objConn.Close
Set objConn = Nothing
EH:
Let lErrorCode = Err.Number
End Function
Thanks in advance
--Brian
Blauther@SoundSoftware.cc