zoukankan      html  css  js  c++  java
  • 使用VSTS创建SQL Server的functions (UserDefined Function)

    没想到,头一次使用VSTS创建SQL Server的function,就遇到个大的问题,VSTS(2008)默认的function是不支持对数据库的访问,只能够对传入的几个参数进行各种操作。如:
     image

    如果在其中对数据库操作,打开一个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)], 如:

    image

  • 相关阅读:
    指针与数组
    深入函数
    到底是使用指针还是引用 ,混合使用以及易错点
    返回值作为标志
    c++的引用(二)
    内联函数
    c++的引用
    指针总结以及常量指针与指向常量的指针与指向常量的常指针
    c++中的 堆和栈
    Java Messages Synchronous and Asynchronous
  • 原文地址:https://www.cnblogs.com/skywind/p/1148491.html
Copyright © 2011-2022 走看看