Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 311540 - Last Review: May 16, 2007 - Revision: 3.5
A "COMPUTE BY statements not supported" exception occurs when you use the COMPUTE BY clause in SQL Server
This article was previously published under Q311540
This article refers to the following Microsoft .NET
Framework Class Library namespaces:
- System.Data.OleDb
- System.Data.SqlClient
On This Page
SYMPTOMS
When you attempt to use the COMPUTE BY clause with the
Microsoft SQL Server .NET Data Provider, you receive the following exception:
An unhandled exception of type
'System.InvalidOperationException' occurred in system.data.dll.
Additional information: COMPUTE BY statements not supported.
Note The COMPUTE BY clause in a SQL Server statement generates
subtotals within the result set.
CAUSE
This behavior is caused by a limitation of the SQL Server
.NET Data Provider.
The SQL Server .NET Data Provider does not
support all SQL syntax statements.
RESOLUTION
To resolve this issue, use ADO through COM Interop, or use
the OLE DB .NET Data Provider.
STATUS
This
behavior is by design.
MORE INFORMATION
Steps to Reproduce the Problem
- Create a stored procedure "myProc" in the Pubs database by running the following query in SQL Server Query
Analyzer:
CREATE PROCEDURE MyProc AS
SELECT Type, Price
FROM Titles
ORDER BY Type
COMPUTE SUM(Price) BY Type
GO
- Start Visual Studio .NET.
- Create a new Windows application in Visual Basic
.NET.
- Make sure that your project contains a reference to the System.Data namespace.
- Place a command button on Form1. Change the Name property of the button to "btnTest" and the Text property to "Test."
- Use the Imports statement on the System and System.Data namespaces so that you are not required to qualify declarations
in those namespaces later in your code. Add this to the General Declarations
section of Form1, as follows:
Imports System
Imports System.Data.OleDb
Imports System.Data.SqlClient
- Paste the following code in the code window after the
region "Windows Form Designer generated code":
Note
You must replace User ID <user name> with an account that has the
appropriate permissions to perform these operations on the database.
Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTest.Click
Dim myConnString As String = _
"User ID=<username>;password=<strong password>;Initial Catalog=pubs;Data Source=myServer"
Dim myConnection As New SqlConnection(myConnString)
Dim myCommand As New SqlCommand()
Dim myReader As SqlDataReader
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Connection = myConnection
myCommand.CommandText = "MyProc"
Dim RecordCount As Integer
myConnection.Open()
myReader = myCommand.ExecuteReader
While myReader.Read()
'Logic to process data
RecordCount = RecordCount + 1
End While
End Sub
- Modify the Connection string (myConnString) as appropriate
for your environment.
- Save your project. On the Debug menu, click Start to run your project.
- Click Test.
Notice that an exception is generated when you attempt
to run the command.
REFERENCES
For more information about ADO.NET objects and syntax, see
the Microsoft .NET Framework SDK Documentation, or browse to the following MSDN
Web site:
For more details about the .NET Framework and the COM Interop
layer, browse to the following MSDN Web site:
APPLIES TO
- Microsoft ADO.NET 2.0
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft Visual Basic .NET 2002 Standard Edition
- Microsoft Visual Basic .NET 2003 Standard Edition
- Microsoft SQL Server 2000 Standard Edition
- Microsoft SQL Server 7.0 Standard Edition
| kbtshoot kberrmsg kbnofix kbprb kbsqlclient kbstoredproc kbsystemdata KB311540 |
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