Microsoft Knowledge Base Email Alertz

KBAlertz.com: (827993) - Microsoft Visual Studio .NET Server Explorer generates SqlCommand objects that contain SqlParameter fields with incorrect data types when one of the following scenarios is true: You connect to the Microsoft SQL Server database by using Visual Studio...

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: 827993 - Last Review: May 2, 2006 - Revision: 1.3

Visual Studio .NET Server Explorer generates parameters of incorrect data types

On This Page

SYMPTOMS

Microsoft Visual Studio .NET Server Explorer generates SqlCommand objects that contain SqlParameter fields with incorrect data types when one of the following scenarios is true:
  • You connect to the Microsoft SQL Server database by using Visual Studio .NET Server Explorer and then you drag a database table that contains columns where the data type is text or ntext to the form designer.
  • You connect to the SQL Server database by using Visual Studio .NET Server Explorer and then you drag a stored procedure that contains parameters where the data type is text or ntext to the form designer.
Note This problem also occurs for columns or parameters where the data type is image, smallmoney, smalldatetime, or binary.

CAUSE

Visual Studio .NET Server Explorer uses an OLE DB provider to connect to a computer that is running SQL Server. The OLE DB provider does not distinguish between varchar columns and text columns of a data table. Therefore, the size of the parameters that are generated by Server Explorer is correct, but the data type is not correct.

RESOLUTION

To resolve the problem, manually change the data type of the parameters to text or to ntext in the generated code as appropriate for the data type on the computer that is running SQL Server.

Note If you do not manually change the data type of your text and ntext parameters in the generated code, you may receive the error that is mentioned in the following article:
827366  (http://kbalertz.com/Feedback.aspx?kbNumber=827366/ ) "Invalid Buffer Received from Client" Error Message in SQL Server Log When You Use SQL Server .NET Provider Classes

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start SQL Query Analyzer (or SQL Server Enterprise Manager), and then create a new stored procedure in the SQL Northwind sample database as follows:
    USE Northwind
    Go
    CREATE proc TestProc
    @ntextParam ntext,
    @textParam text
    as
    return 1
    Go
    
  2. Start Microsoft Visual Studio .NET.
  3. On the File menu, point to New, and then click Project.
  4. Click Visual Basic Projects or Visual C# Projects under Project Types, and then click Windows Application under Templates. By default, Form1 is created.
  5. On the View menu, click Server Explorer.
  6. In Server Explorer, right-click Data Connections, and then click Add Connection.
  7. In the Data Link Properties dialog box, type your local SQL Server name in the Select or enter a server name text box.
  8. Type your local SQL Server user name in the User name box, and then type your password in the Password text box.
  9. In the Select the database on the server box, click Northwind, and then click OK.
  10. In Server Explorer, expand your local SQL Server data connection, and then expand Stored Procedures.
  11. In Server Explorer, drag the TestProc stored procedure from Stored Procedures to Form1.
  12. On the View menu, click Code.
  13. In the code editor, expand Windows Form Designer generated code.

    In the SqlCommand1 object, you see that the data type of the ntextParam parameter is NVarCharand the data type of the textParam parameter is VarChar.

REFERENCES

For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
316649   (http://kbalertz.com/Feedback.aspx?kbNumber=316649/ ) How to use the Server Explorer in Visual Studio .NET and Visual Studio 2005

304959   (http://kbalertz.com/Feedback.aspx?kbNumber=304959/ ) HOW TO: Use Visual Studio .NET Server Explorer to Access Data


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
  • Microsoft Visual Studio .NET 2002 Enterprise Architect
  • Microsoft Visual Studio .NET 2002 Enterprise Developer
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Visual Studio .NET 2002 Academic Edition
  • Microsoft ADO.NET 1.1
  • Microsoft ADO.NET 1.0
Keywords: 
kbsqlclient kbdatetime kbtable kbstoredproc kbprb KB827993
       

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