ACC2000: Output of Stored Procedure Truncated in Access Client/Server

ID: Q232562


The information in this article applies to:

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access project (.adp).


SYMPTOMS

When you run certain stored procedures from a Microsoft Access project, the output of the procedure is truncated in Datasheet view. If you run the same procedure from one of the SQL Server Client Tools, all rows are returned as expected.


CAUSE

If a stored procedure returns multiple result sets in its output, an Access project returns only the first result set to Datasheet view. The user interface in an Access project is not designed to return multiple result sets.


RESOLUTION

Use alternate tools to run stored procedures that return multiple result sets, such as SQL Server Query Analyzer or OSQL.


MORE INFORMATION

To determine if Access Client/Server can display the entire output of a particular stored procedure, follow these steps.

NOTE: The sample code in this article uses Microsoft ActiveX Data Objects. For this code to run properly, you need to reference the Microsoft ActiveX Data Objects 2.1 Library.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
  1. Open an Access project that is connected to the user database which contains the stored procedure that you want to examine. If you need to test a system stored procedure, open any Access project connected to a user database.


  2. Create a module and type the following line in the Declarations section if it is not already there:


  3. 
    Option Explicit 
  4. Type the following procedure:


  5.  
    Sub CheckOutput(strProcName As String)
        
       Dim conn As New adodb.Connection
       Dim com As New adodb.Command
       Dim rs As New adodb.Recordset
       Dim i
        
       On Error GoTo errorTrapper
       
       Set conn = CurrentProject.Connection
       com.ActiveConnection = conn
        
       With com
          .CommandText = strProcName
          .CommandType = adCmdStoredProc
       End With
        
       Set rs = com.Execute
           
       Do Until rs Is Nothing
          i = i + 1
          Set rs = rs.NextRecordset
          If i > 1 Then
             MsgBox "Stored Procedure " & strProcName & _
               " contains more than one resultset. " & vbCrLf & _
               "The results will therefore be truncated when displayed.", _
               vbInformation
             Exit Sub
          End If
       Loop
            
       Exit Sub
        
    errorTrapper:
       If Err.Number = 3251 Then
          MsgBox "Stored Procedure " & strProcName & _
            " contains only one resultset. " & vbCrLf & _
            "It therefore should be displayed correctly.", _
            vbInformation
       Else
          MsgBox Err.Description & Err.Number, vbCritical, "Error"
       End If
        
    End Sub 
  6. Open the Immediate window and type the following line of code, substituting StoredProcName with the name of the stored procedure that you want to examine:


  7. 
    Call Checkoutput("StoredProcName") 
    Press ENTER.

Steps to Reproduce Behavior

  1. Open an Access project connected to the sample database NorthwindCS.adp.


  2. Use the following SQL to create a new stored procedure:


  3. 
       CREATE PROCEDURE "TestSProc"
       AS
       EXEC sp_help 'Customers' 
    Save the stored procedure.

  4. Run the stored procedure and note that one row is returned in Datasheet view.


  5. Open SQL Server Query Analyzer, connect to the NorthwindCS database on your SQL Server, and run the following code:


  6. 
    EXEC TestSproc 
Note that approximately 23 rows are returned.


REFERENCES

For more information about rules, SQL Server Query Analyzer, or OSQL, refer to SQL Server 7.0 Books Online, which is available for download from the following Microsoft Web site:

http://support.microsoft.com/download/support/mslfiles/sqlbol.exe

Additional query words: prb


Keywords          : kbdta AccessCS 
Version           : WINDOWS:2000
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: July 22, 1999