Microsoft Knowledge Base Email Alertz

KBAlertz.com: (827366) - When you use a Microsoft .NET Framework SqlClient class, you receive the following error message in the Microsoft SQL Server 2000 error log: Error: 17805, Severity: 20, State: 3 Invalid buffer received from client. You receive the following...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 827366 - Last Review: April 18, 2007 - Revision: 3.3

"Invalid Buffer Received from Client” error message in SQL Server log when you use SQL Server .NET provider classes

SYMPTOMS

When you use a Microsoft .NET Framework SqlClient class, you receive the following error message in the Microsoft SQL Server 2000 error log:
Error: 17805, Severity: 20, State: 3
Invalid buffer received from client.
You receive the following corresponding error messages in the Microsoft .NET Framework client application:
System.Data.SqlClient.SqlException: A severe error occurred on the current command. The results, if any, should be discarded

CAUSE

This behavior occurs if one of the following scenarios is true:
  • You use a SqlClient class in a Finalize method or in a C# destructor.
  • You do not specify an explicit SQLDbType enumeration when you create a SqlParameter object. When you do not specify an explicit SQLDbType enumeration, the Microsoft .NET Framework Data Provider for SQL Server (SqlClient) tries to select the correct SQLDbType enumeration based on the data that is passed. SqlClient is unsuccessful.
  • You declare an instance of the SqlClient class to be static in C# or to be shared in Visual Basic. The instance can be accessed concurrently from more than one thread in the application.

    Note In the ASP.NET environment or in some other environments, concurrent access is possible even if no additional threads are created explicitly in the application code.
  • The size of the parameter that you explicitly specify in the .NET Framework code is more than the maximum size that you can use for the data type in SQL Server.

    For example, according to SQL Server Books Online, nvarchar is a variable-length Unicode character data of n characters. "n" must be a value from 1 through 4000. If you specify a size that is more than 4000 for an nvarchar parameter, you receive the error message that is described in the "Symptoms" section.
The following code also demonstrates how these errors might occur:
Stored Procedure
--------------------------

CREATE PROCEDURE spParameterBug @myText Text AS
            Insert Into ParameterBugTable (TextField) Values (@myText)

Code
-------
static void Main(string[] args)
{
       string dummyText=string.Empty;
       for (int n=0; n < /*80*/ 3277; n++)   // change this to 80 to receive the second error that is mentioned earlier in this article.
       {
             dummyText += "0123456789";
       }

        // TO DO: Change data source to match your SQL Server:

       SqlConnection con= new SqlConnection("data source=myserver;Initial Catalog=mydb;Integrated Security=SSPI;persist security info=True;packet size=16384");
       SqlCommand cmd = new SqlCommand("SpParameterBug", con);
      con.Open();
           // Causes error 17805:
      SqlParameter param2 =new SqlParameter("@myText", dummyText);
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Parameters.Add(param2);
      try
      {
          cmd.ExecuteNonQuery();
      } 
      catch (Exception err)
      {
         Console.WriteLine(err.ToString());
      }

      Console.ReadLine();

}

RESOLUTION

To resolve these errors, make sure that you do the following:
  • Do not use a SqlClient class in a Finalize method or in a C# destructor.
  • Specify the SqlDbType enumeration for the SqlParameter object so that there is no inferred type.
  • Specify a parameter size that is within the limits of the data type.

REFERENCES

For more information about the maximum size for different data types, visit the following Microsoft Developer Network (MSDN) Web sites:
http://msdn2.microsoft.com/en-us/library/aa276823(SQL.80).aspx (http://msdn2.microsoft.com/en-us/library/aa276823(SQL.80).aspx)
http://msdn2.microsoft.com/en-us/library/aa258271(SQL.80).aspx (http://msdn2.microsoft.com/en-us/library/aa258271(SQL.80).aspx)

APPLIES TO
  • Microsoft .NET Framework 1.0
Keywords: 
kbprb KB827366
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please