p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Microsoft SQL Server 2008 Programming (http://p2p.wrox.com/forumdisplay.php?f=499)
-   -   Runtime Error on User Defined Aggregate (http://p2p.wrox.com/showthread.php?t=80406)

Monchkrit August 6th, 2010 10:10 AM

Runtime Error on User Defined Aggregate
I am getting a runtime error on the sample code from Chapter 10. The system assembles and creates the User Defined Aggregate, when when I go to run it I get a nasty error. The output is pasted below. Can you please help to me figure out how to get around this problem?

Thank you,
Donny Buckman

GroupKey Product
----------- ----------------------
Msg 6522, Level 16, State 2, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate "Product":
System.InvalidOperationException: Data access is not allowed in this context. Either the context is a function or method not marked with DataAccessKind.Read or SystemDataAccessKind.Read, is a callback to obtain data from FillRow method of a Table Valued Function, or is a UDT validation method.
at System.Data.SqlServer.Internal.ClrLevelContext.Che ckSqlAccessReturnCode(SqlAccessApiReturnCode eRc)
at System.Data.SqlServer.Internal.ClrLevelContext.Get CurrentContext(SmiEventSink sink, Boolean throwIfNotASqlClrThread, Boolean fAllowImpersonation)
at Microsoft.SqlServer.Server.InProcLink.GetCurrentCo ntext(SmiEventSink eventSink)
at Microsoft.SqlServer.Server.SmiContextFactory.GetCu rrentContext()
at Microsoft.SqlServer.Server.SqlContext.get_CurrentC ontext()
at Microsoft.SqlServer.Server.SqlContext.get_Pipe()
at Product.Terminate()

Monchkrit August 6th, 2010 01:04 PM

Found the problem
When I moved forward in the book to the "Custom Data Types" section Mr. Vieira has us download the code from this site, so I did. At that point I decided to examine the ExampleAggregate code to see if it would display the same error, and alas it worked just fine. On comparison between the code in the sample download and that printed in the book I found the problem.

On page 324 is a line that I thought looked strange when I read it, and then even more strange when I typed it into the C# struct. That line reads:

SqlContext.Pipe.Send("WARNING: Aggregate values exist and were ignored");
You see, the odd thing is there is nothing in the function to determine that condition. Plus, there probably is something that has to do with checking on the data table which from the error message appears to be prohibited by this type of assembly. Anyway, that line is not present in the downloaded code, which is why it runs as expected.

Donny Buckman

All times are GMT -4. The time now is 08:19 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.