Hello,
I am having trouble with a SQL Server 2000 SP that accepts input parameters. I am using an Access 2007 accdb front end. I can run update and insert SP’s no problem, but cannot get select SP’s to return a record set. When doing a record count after running the code, I get a value of ‘-1’. Obviously, when I then try to set this as the recordset for the form, it fails (no error checking at the moment, but the issue is the SP is not returning any rows). I know the SP works as executing it with the same parameters from Enterprise Manager returns over 1000 records. The code I’m using is:
Dim cnn As ADODB.Connection Dim cmd As ADODB.Command Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset Set cnn = New ADODB.Connection Set cmd = New ADODB.Command cnn.Open "Provider=sqloledb;Data Source=PLATINUM2SMNS;Initial Catalog=SMNS TEST;Integrated Security=SSPI;" With cmd Set .ActiveConnection = cnn .CommandType = adCmdStoredProc .CommandText = "qryClients_SQL" .Parameters.Append .CreateParameter("@Archive", adInteger, adParamInput, , 0) .Parameters.Append .CreateParameter("@CStatus", adVarChar, adParamInput, 10, "Active") End With rs.Open cmd, , adOpenStatic, , adCmdStoredProc MsgBox rs.RecordCount Set Forms!Form1.Recordset = rs
Note that I am hard-coding input parameters for testing purposes. Just for interest, the Stored Procedure is as follows:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Gareth -- Create date: 03-06-2010 -- Description: Test select query -- ============================================= ALTER PROCEDURE qryClients_SQL @Archive int = 0, @CStatus varchar(10) AS BEGIN SET NOCOUNT ON; SELECT Nursing_ID_Number, Surname, Given_Name FROM tblClientsCommon WHERE Archive = @Archive AND CStatus = @CStatus ORDER BY Surname ASC END GO
If I run the following code from Enterprise Manager I get values returned without any issues:
exec qryClients_SQL 0,"Active"
I’ve searched numerous different forums, tutorials and so forth and they all have variations on the above but I keep getting the same result – no returned rows. Moving to an ADP would solve pretty much all of these issues, but that is not an option in this database at present.
Anybody have any suggestions?
Thanks
toncc