Unexpectedly, the first time I used vsts to create SQL server functions, I encountered a big problem. The default function of vsts (2008) does not support database access, you can only perform various operations on the input parameters. For example:
If a sqlconnection is enabled for the database, the following error occurs:
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.
According to the error message, we know (I learned it after Google for a long time) that dataaccess = dataaccesskind is required. read, systemdataaccess = systemdataaccesskind. read Mark, that is, you cannot write only [Microsoft. sqlserver. server. sqlfunction] (default in this example). If you want to operate a database, you must write it as [Microsoft. sqlserver. server. sqlfunction (dataaccess = dataaccesskind. read, systemdataaccess = systemdataaccesskind. read)], such: