Wrox Programmer Forums
BOOK: Professional Microsoft SQL Server 2008 Programming
This is the forum to discuss the Wrox book Professional Microsoft SQL Server 2008 Programming by Robert Vieira; ISBN: 9780470257029
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Microsoft SQL Server 2008 Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 6th, 2010, 10:10 AM
Registered User
Join Date: Jul 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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()
Old August 6th, 2010, 01:04 PM
Registered User
Join Date: Jul 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Smile 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
ADODB.Connection user-defined type not defined Wall st Guru Excel VBA 2 March 26th, 2014 03:44 PM
User-Defined Type Error - Re: File Dialog Coby Access VBA 1 January 16th, 2008 09:42 AM
User-defined type not defined (Icecream.mdb) dloren01 BOOK: Beginning Access VBA 0 June 22nd, 2005 10:36 PM
User Defined Error Messages pvasudevan SQL Server 2000 0 March 18th, 2004 08:46 AM
User defined Aggregate function to calculate skew akmhasan Oracle 0 July 20th, 2003 12:44 AM

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