Microsoft KB Archive/896373

= You may receive a SqlException error message when your .NET Framework client application calls a stored procedure that has an output parameter of the nvarchar type and the application uses the SqlClient class to work with SQL Server 2000 =

Article ID: 896373

Article Last Modified on 11/2/2007

-

APPLIES TO


 * Microsoft SQL Server 2000 Standard Edition
 * Microsoft SQL Server 2000 Personal Edition
 * Microsoft SQL Server 2000 Enterprise Edition
 * Microsoft SQL Server 2000 Desktop Engine (Windows)
 * Microsoft SQL Server 2000 Developer Edition

-



Bug #: 469978 (SQL Server 8.0)



SYMPTOMS
When you use the SqlClient class in a Microsoft .NET Framework client application to work with Microsoft SQL Server 2000 hotfix build 2000.80.811 or a later version, you may receive an error message if the following conditions are true:
 * Your application tries to call a stored procedure.
 * The output parameter of the stored procedure is an nvarchar type.
 * The application sets the output parameter of the stored procedure to a value that is more than 4,000.

The text is of the error message is similar to the following:

System.Data.SqlClient.SqlException: A severe error occurred on the current command. The results, if any, should be discarded.

The following error message also appears in the SQL Server 2000 error log:

Error: 17805, Severity: 20, State: 3

Invalid buffer received from client.



CAUSE
According to SQL Server Books Online, the nvarchar data type is a variable-length Unicode character data of  characters. The placeholder  must be a value from 1 through 4,000. In this scenario, SQL Server resets the client connection if you try to set the size to a value that is more than 4,000 characters. Then, you receive the error message that is mentioned in the &quot;Symptoms&quot; section.

Note SQL Server 2000 hotfix builds that are earlier than 2000.80.811 do not tighten the boundaries of the parameter size of the nvarchar data type.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the problem
  Create a stored procedure on the computer that is running SQL Server 2000 by using the following statement: CREATE PROCEDURE sp_mytest @result nvarchar(4000) output AS           SET @result= 'Dummy testing'   Create a Microsoft Visual C# Console Application that contains the following code:

Note Before you run the code, replace the DBServer and DBName variables with the correct names of your computer that is running SQL Server and your database. using System; using System.Data; using System.Data.SqlClient;

namespace SqlTest {

class Class1 {       private static string DBServer = &quot;SQLServerName&quot;; private static string DBName = &quot;DatabaseName&quot;;

[STAThread] static void Main(string[] args) {           try {

string connectionString = &quot;Data Source=&quot; + DBServer+ &quot;;Integrated Security=SSPI;Initial Catalog=&quot;+DBName;

SqlConnection sqlConn = new SqlConnection(connectionString);

SqlParameter param = null; string cmdText = &quot;sp_mytest&quot;; SqlCommand cmd = sqlConn.CreateCommand; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText= cmdText;

param = cmd.Parameters.Add(&quot;@result&quot;,SqlDbType.NVarChar); param.Direction = ParameterDirection.Output; param.Size = 6000; sqlConn.Open; cmd.ExecuteNonQuery; Console.WriteLine (param.Value.ToString); sqlConn.Close; }           catch(SqlException  e)            { Console.WriteLine(e.Message ); }

}   } }  Build and then run the Visual C# Console Application. You receive the error messages that are mentioned in the &quot;Symptoms&quot; section.

Additional query words: GNE bind SP TDS ADO.NET

Keywords: kberrmsg kbprb kbtshoot KB896373

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.