SET statements do not have connection-wide ccope with ExecuteReader() of SQLCommand class (316889)
The information in this article applies to:
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft ADO.Net 2.0
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic .NET (2003)
- Microsoft Visual Basic 2005
This article was previously published under Q316889
This article refers to the following Microsoft .NET Framework Class Library namespaces:
- System.Data
- System.Data.SqlClient
SYMPTOMS
When you are using SET statements that are followed by resultsets that are returning statements such as SELECT, existing Microsoft SQL tools return non-resultset queries. This is not true when you are using the SqlCommand.ExecuteReader method. When SET statements are used with SqlCommand.ExecuteReader, the SQL statements that contain SET statements such as "SET statistics profile on" return results from the set statements. The preceding SQL statements (such as SELECT * FROM TableA) that are executed in the same connection do not see results from the "SET statistics profile on" statement. "SET statistics profile on" is expected to be scoped to the connection. The real scope that is seen here ("SET statistics profile on") is scoped to the statement.
CAUSE
The ExecuteReader method of the SqlCommand object does not support the use of SET statements. When you are using SET statements, they are only scoped to the statement and not to the connection.
RESOLUTION
When you are executing queries that do not return results, use the ExecuteNonQuery method because this method has a connection-wide scope.
Execute Command Active SET statements
---------- ------------------ ---------------------
ExecuteReader Set xxx SELECT ... xxx
ExecuteNonQuery Set yyy UPDATE ... yyy
ExecuteReader Set zzz SELECT ... yyy zzz
ExecuteNonQuery UPDATE ... yyy
The current connection would have yyy set.
STATUSThis behavior is by design.REFERENCES
For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
313483 Roadmap for ADO.NET DataAdapter objects
Modification Type: | Minor | Last Reviewed: | 10/3/2006 |
---|
Keywords: | kbenv kbnofix kbprb kbSqlClient kbSystemData KB316889 kbAudDeveloper |
---|
|