Error when you try to call the Prepare method before you add parameters: "An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll" (310368)
The information in this article applies to:
- Microsoft ADO.Net 2.0
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic 2005
- Microsoft SQL Server 7.0
This article was previously published under Q310368 For a Microsoft Visual C# .NET version of this
article, see
311348. This article refers
to the following Microsoft .NET Framework Class Library namespaces:
- System.Data.OleDb
- System.Data.SqlClient
SYMPTOMS 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: An unhandled exception of type
'System.Data.SqlClient.SqlException' occurred in system.data.dll.
Additional information: System error. This problem does not occur in
SQL Server 2000. CAUSE 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. RESOLUTION To resolve this problem, do not call the Prepare method until after you add the parameters. REFERENCES For more information on ADO.NET objects and syntax, refer
to the following Microsoft .NET Framework Software Development Kit (SDK)
documentation:
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbtshoot kberrmsg kbnofix kbprb kbSqlClient kbSystemData KB310368 kbAudDeveloper |
---|
|