Article ID: 955629 - View products that this article applies to.
After you upgrade to Microsoft SQL Server 2008 or to Microsoft SQL Server 2008 R2, when you run an application, a script, or a functionality from an earlier Microsoft SQL Server installation that uses common language runtime (CLR) features, you receive an error message that resembles the following error message:
For example, this problem may occur in the following scenarios.
Msg 6522, Level 16, State 1, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate routine name:
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.
Scenario 1You use a method that has the following characteristics:
Scenario 2You use the INIT method in a CLR table-valued function that performs impersonation.
Scenario 3You use the FillRow method in a CLR table-valued function that performs impersonation.
This problem occurs because of a change in the Database Engine features in SQL Server 2008 and in SQL Server 2008 R2.
To work around the problem as described in the scenarios in the "Symptoms" section, use one of the following methods.
Method 1: To work around this problem in Scenario 1 and in Scenario 2To work around this problem, add the DataAccessKind.Read property to the method.
Method 2: To work around this problem in Scenario 3To work around this problem, do the following:
For information about the DataAccessKind.Read property and other custom attributes for CLR routines, visit the following Microsoft TechNet Web site:
http://technet.microsoft.com/en-us/library/ms131050.aspxFor information about breaking changes in the Database Engine features in SQL Server 2008, visit the following Microsoft TechNet Web site:
Article ID: 955629 - Last Review: March 19, 2009 - Revision: 2.1
Contact us for more help