Microsoft KB Archive/884806

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

Article ID: 884806

Article Last Modified on 9/8/2004

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * 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:   Run the following command in SQL Query Analyzer: use master go sp_dropextendedproc 'xp_proc' dbcc xp_proc (free) go   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 ;   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;  Rebuild the extended stored procedure project. Copy the XP_Proc.dll file to the \MSSQL\Binn folder on the computer that is running Microsoft SQL Server.

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

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to reproduce the behavior
<ol> Follow these steps to create an extended stored procedure DLL project by using Microsoft Visual C++ .NET: <ol style="list-style-type: lower-alpha;"> Start Microsoft Visual Studio .NET 2003.</li> On the File menu, point to New, and then click Project.</li> Under Project Types, click Visual C++ Projects, and then click Extended Stored Procedure DLL under Templates.</li> Type XP_Proc in the Name box, and then click OK.</li> In the Extended Stored Proc Wizard - XP_Proc dialog box, click Finish.</li> In Solution Explorer, right-click proc.cpp, and then click Open.</li>  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 ; </li>  Replace these lines of code with the following code: srv_senddone(srvproc, SRV_DONE_ERROR | SRV_DONE_MORE, 0, 0); return XP_ERROR ; </li> On the Build menu, click Build Solution.</li></ol> </li> Follow these step to add the extended stored procedure to the SQL Server database: <ol style="list-style-type: lower-alpha;"> Copy the XP_Proc.dll file to the \mssql\Binn folder on the computer that is running SQL Server.</li>  Run the following command by using SQL Query Analyzer: use master go sp_addextendedproc 'xp_proc','XP_Proc.dll' </li></ol> </li> Follow these steps to create a console application project by using Microsoft Visual C# .NET: <ol style="list-style-type: lower-alpha;"> Start Microsoft Visual Studio .NET 2003.</li> 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.</li> <li> Paste the following code at the beginning of the Class1.cs file: using System.Data.SqlClient; using System.Data; </li> <li> 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(&quot;server=yourservername;uid=yourusername;pwd=yourpassword;database=master&quot;); try {   conn.Open; string strSql = &quot;exec xp_proc&quot;; System.Data.SqlClient.SqlCommand cmd= new System.Data.SqlClient.SqlCommand(strSql,conn); cmd.CommandType = CommandType.Text; filler = new SqlDataAdapter(cmd); filler.Fill(d,&quot;Results&quot;); conn.Close; } catch(SqlException e) { int i = e.GetHashCode; string str=e.Message; System.Console.WriteLine(str); System.Console.ReadLine; conn.Close; } Note ,  , and   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. </li> <li>On the Build menu, click Build Solution.</li> <li>On the Debug menu, click Start. You notice the behavior that is mentioned in the &quot;Symptoms&quot; section.</li></ol> </li></ol>

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).

<div class="references_section">