本文共 946 字,大约阅读时间需要 3 分钟。
没想到,头一次使用VSTS创建SQL Server的function,就遇到个大的问题,VSTS(2008)默认的function是不支持对数据库的访问,只能够对传入的几个参数进行各种操作。如:
如果在其中对数据库操作,打开一个SqlConnection,则会出问题,提示:
A .NET Framework error occurred during execution of user defined routine or aggregate 'Your_Function':
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.根据错误提示,我们得知(我是google了好久才得知的),需要做DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read 这一标记,即不能只写[Microsoft.SqlServer.Server.SqlFunction] (此处为系统默认), 如果要对数据库操作,要写成 [Microsoft.SqlServer.Server.SqlFunction(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)], 如:
本文转自Jack Niu博客园博客,原文链接:http://www.cnblogs.com/skywind/archive/2008/04/11/1148491.html,如需转载请自行联系原作者