You receive an exception when you call an extended stored procedure from a Visual Studio .NET application (884806)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition

SYMPTOMS

When you call an extended stored procedure from a Microsoft Visual Studio .NET application by using the SqlClient namespace, you may receive the following exception message:
A severe error occurred on the current command. The results, if any, should be discarded.

WORKAROUND

To work around this problem, follow these steps:
  1. Run the following command in SQL Query Analyzer:
    use master
    go
    sp_dropextendedproc 'xp_proc'
    dbcc xp_proc (free)
    go
  2. Locate the following lines of code in the proc.cpp file in the extended stored procedure project (XP_Proc):
    srv_senddone(srvproc, SRV_DONE_ERROR | SRV_DONE_MORE, 0, 0);
    return XP_ERROR ;
    
  3. Replace these lines of code with the following code:
    srv_senddone(srvproc, SRV_DONE_MORE | SRV_DONE_COUNT, (DBUSMALLINT)0, (DBINT)i);
    return XP_NOERROR;
  4. Rebuild the extended stored procedure project.
  5. Copy the XP_Proc.dll file to the sqlserverpath\MSSQL\Binn folder on the computer that is running Microsoft SQL Server.

    Note sqlserverpath is a placeholder for the path of the folder where SQL Server is installed.
  6. Run the following command in SQL Query Analyzer:
    use master
    go
    sp_addextendedproc 'xp_proc','XP_Proc.dll'
    

STATUS

This behavior is by design.

MORE INFORMATION

Steps to reproduce the behavior

  1. Follow these steps to create an extended stored procedure DLL project by using Microsoft Visual C++ .NET:
    1. Start Microsoft Visual Studio .NET 2003.
    2. On the File menu, point to New, and then click Project.
    3. Under Project Types, click Visual C++ Projects, and then click Extended Stored Procedure DLL under Templates.
    4. Type XP_Proc in the Name box, and then click OK.
    5. In the Extended Stored Proc Wizard - XP_Proc dialog box, click Finish.
    6. In Solution Explorer, right-click proc.cpp, and then click Open.
    7. Locate the following lines of code in the proc.cpp file:
      srv_senddone(srvproc, SRV_DONE_MORE | SRV_DONE_COUNT, (DBUSMALLINT)0, (DBINT)i);
      return XP_NOERROR ;
    8. Replace these lines of code with the following code:
      srv_senddone(srvproc, SRV_DONE_ERROR | SRV_DONE_MORE, 0, 0);
      return XP_ERROR ;
      
    9. On the Build menu, click Build Solution.
  2. Follow these step to add the extended stored procedure to the SQL Server database:
    1. Copy the XP_Proc.dll file to the sqlserverpath\mssql\Binn folder on the computer that is running SQL Server.
    2. Run the following command by using SQL Query Analyzer:
      use master
      go
      sp_addextendedproc 'xp_proc','XP_Proc.dll'
      
  3. Follow these steps to create a console application project by using Microsoft Visual C# .NET:
    1. Start Microsoft Visual Studio .NET 2003.
    2. Under Project Types, click Visual C# Projects, and then click Console Application under Templates. By default, a file that is named Class1.cs is added to the project.
    3. Paste the following code at the beginning of the Class1.cs file:
      using System.Data.SqlClient;
      using System.Data;
    4. Paste the following code in the Main function of the Class1.cs file:
      SqlDataAdapter filler;
      DataSet d = new DataSet();
      System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("server=yourservername;uid=yourusername;pwd=yourpassword;database=master");
      try
      {
      	conn.Open();
      	string strSql = "exec xp_proc";
      	System.Data.SqlClient.SqlCommand cmd= new System.Data.SqlClient.SqlCommand(strSql,conn);
      	cmd.CommandType = CommandType.Text;
      	filler = new  SqlDataAdapter(cmd);
      	filler.Fill(d,"Results");
      	conn.Close();
      }
      catch(SqlException e)
      {
      	int i = e.GetHashCode();
      	string str=e.Message;
      	System.Console.WriteLine(str);
      	System.Console.ReadLine();
      	conn.Close();
      }
      
      Note yourservername, yourusername, and yourpassword are the placeholders for the name of the computer that is running SQL Server, the user name to connect to the computer that is running SQL Server, and the associated password for the specified user name, respectively.
    5. On the Build menu, click Build Solution.
    6. On the Debug menu, click Start. You notice the behavior that is mentioned in the "Symptoms" section.
You do not receive an exception when you call the extended stored procedure in the following scenarios:
  • You call the extended stored procedure from SQL Query Analyzer.
  • You call the extended stored procedure from a Visual Studio .NET application by using the System.Data.OleDb namespace.
  • You call the extended stored procedure from a Visual Studio .NET application by using Microsoft ActiveX Data Object (ADO).

REFERENCES

For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

156099 How to debug an extended stored procedure

190987 How to use extended stored procedures

151596 Extended procedure error: "Cannot find the DLL 'xxx.dll'"


Modification Type:MajorLast Reviewed:9/8/2004
Keywords:kbStoredProc kbSqlClient kbServer kbProvider kbNameSpace kbDLL kbADO kbtshoot kbprb KB884806 kbAudDeveloper