DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 955629 - Last Review: March 19, 2009 - Revision: 2.1

On This Page

SYMPTOMS

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:
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.

System.InvalidOperationException
For example, this problem may occur in the following scenarios.

Scenario 1

You use a method that has the following characteristics:
  • The method uses a CLR user-defined function, a user-defined type (UDT) method, or a user-defined aggregate that performs impersonation.
  • The method uses a large object (LOB) as a parameter.
  • The method does not use the DataAccesKind.Read property on the method.

Scenario 2

You use the INIT method in a CLR table-valued function that performs impersonation.

Scenario 3

You use the FillRow method in a CLR table-valued function that performs impersonation.

CAUSE

This problem occurs because of a change in the Database Engine features in SQL Server 2008 and in SQL Server 2008 R2.

WORKAROUND

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 2

To work around this problem, add the DataAccessKind.Read property to the method.

Method 2: To work around this problem in Scenario 3

To work around this problem, do the following:
  • Remove impersonation from the FillRow method.
  • Do not access external resources by using the FillRow method.
  • Access external resources only by using the INIT method of the table-valued function.

REFERENCES

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.aspx (http://technet.microsoft.com/en-us/library/ms131050.aspx)
For information about breaking changes in the Database Engine features in SQL Server 2008, visit the following Microsoft TechNet Web site:
http://technet.microsoft.com/en-us/library/ms143179(SQL.100).aspx (http://technet.microsoft.com/en-us/library/ms143179(SQL.100).aspx)

APPLIES TO
  • Microsoft SQL Server 2008 Developer
  • Microsoft SQL Server 2008 Enterprise
  • Microsoft SQL Server 2008 Express
  • Microsoft SQL Server 2008 Express with Advanced Services
  • Microsoft SQL Server 2008 Standard
  • Microsoft SQL Server 2008 Web
  • Microsoft SQL Server 2008 Workgroup
  • Microsoft SQL Server 2008 R2 Datacenter
  • Microsoft SQL Server 2008 R2 Developer
  • Microsoft SQL Server 2008 R2 Enterprise
  • Microsoft SQL Server 2008 R2 Express
  • Microsoft SQL Server 2008 R2 Express with Advanced Services
  • Microsoft SQL Server 2008 R2 Standard
  • Microsoft SQL Server 2008 R2 Standard Edition for Small Business
  • Microsoft SQL Server 2008 R2 Workgroup
Keywords: 
sql2008relnotedatabaseengine sql2008relnote kbprogramming kbautomation kberrmsg kbtshoot kbexpertiseinter kbprb KB955629
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support