Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
Error message occurs in SQL Server 7.0 when you call the Command.Prepare method before you add parameters by using Visual C# .NET: "An unhandled exception of type"
Article ID: 311348 - View products that this article applies to.
This article was previously published under Q311348
For a Microsoft Visual Basic .NET version of this article, see 310368
This article refers to the following Microsoft .NET Framework Class Library namespaces:
When you create a parameterized command against Microsoft SQL Server 7.0, if you call the Prepare method before you add parameters to the command, you receive the following error message:
This problem does not occur in SQL Server 2000.
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll.
Additional information: System error.
This problem occurs in SQL Server 7.0 because, by design, you cannot run the Prepare method before you add parameters. This applies to most database systems.
SQL Server 2000 does not generate the above-mentioned exception because it does not run Prepare until the first command is executed. This optimization prevents the overhead of Prepare if no commands are subsequently executed.
To resolve this problem, do not call the Prepare method until after you add the parameters.
Steps to reproduce the behaviorThe sample code to follow uses the Region table of the Northwind sample database.
For more information on ADO.NET objects and syntax, refer to the following Microsoft .NET Framework Software Development Kit (SDK) documentation:
Accessing Data with ADO.NET
Article ID: 311348 - Last Review: May 13, 2007 - Revision: 3.8