Data Access Error: A severe error occurred on the current command

Topics: Data Access Application Block
Jul 31, 2007 at 1:41 PM
Edited Jul 31, 2007 at 1:43 PM
Hi,

I try to execute a simple stored procedure on a SQL Server 2000 using the EntLib 3.1 and get the following error:
A severe error occurred on the current command. The results, if any, should be discarded.
A severe error occurred on the current command. The results, if any, should be discarded.

How can I fix this?



Function
Public Shared Function SelectSingleProductByProductId(ByVal id As Integer) As Entities.Product

Dim db As Database = DatabaseFactory.CreateDatabase()
Dim cmd As SqlCommand = db.GetStoredProcCommand("ProductsSelectSingle")

db.AddInParameter(cmd, "@ProductId", DbType.Int32, id)
db.AddOutParameter(cmd, "@ProductGroupId", DbType.Int32, 4)
db.AddOutParameter(cmd, "@Name", DbType.String, 255)
db.AddOutParameter(cmd, "@Description", DbType.String, 8000)
db.AddOutParameter(cmd, "@Image", DbType.String, 255)
db.AddOutParameter(cmd, "@SalesPrice", DbType.Currency, 8)


Try
db.ExecuteReader(cmd)

Dim _product As New Entities.Product

If Not IsDBNull(cmd.Parameters("@ProductId").Value) Then _product.ProductId = CInt(cmd.Parameters("@ProductId").Value)
If Not IsDBNull(cmd.Parameters("@ProductGroupId").Value) Then _product.ProductGroupId = CInt(cmd.Parameters("@ProductGroupId").Value)
If Not IsDBNull(cmd.Parameters("@Name").Value) Then _product.Name = CStr(cmd.Parameters("@Name").Value)
If Not IsDBNull(cmd.Parameters("@Description").Value) Then _product.Description = CStr(cmd.Parameters("@Description").Value)
If Not IsDBNull(cmd.Parameters("@Image").Value) Then _product.Image = CStr(cmd.Parameters("@Image").Value)
If Not IsDBNull(cmd.Parameters("@SalesPrice").Value) Then _product.SalesPrice = CStr(cmd.Parameters("@SalesPrice").Value)

Return _product

Catch ex As Exception
Throw ex
End Try

End Function

Stored Procedure
CREATE PROCEDURE ProductsSelectSingle
(@ProductId int,
@ProductGroupId int OUTPUT,
@Name varchar(255) OUTPUT,
@Description varchar(8000) OUTPUT,
@Image varchar(255) OUTPUT,
@SalesPrice money OUTPUT)

AS

SELECT

@ProductGroupId = ProductGroupId,
@Name = Name,
@Description = Description,
@Image = Image,
@SalesPrice = SalesPrice

FROM Products

WHERE
(ProductId = @ProductId)
GO

Aug 1, 2007 at 2:03 PM
Edited Aug 1, 2007 at 2:04 PM
Well, you are calling ExecuteReader and not using any DataReader. Since all of your values are returned in OUTPUT variables, maybe you should try ExecuteNonQuery instead?

______________________________________
Matthew Noonan
EasyObjects.NET -- The O/RM for the Enterprise Library
http://www.easyobjects.net