I have the following code:
[SqlFunction(DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read)]
public static int GetInt()
{
int retValue = 0;
using (SqlConnection conn = new SqlConnection("context connection = true"))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select MyInt from SomeTable";
object timeOut = cmd.ExecuteReader(); // <- error happen here
}
return retValue;
}
I get the following exception in
cmd.ExecuteReader();
{"This statement has attempted to access data whose access is restricted by the assembly."}
NET Framework common language runtime (CLR) manages and secures access between different types of CLR and non-CLR objects running within SQL Server. These objects may be called by a Transact-SQL statement or another CLR object running in the server. For more detailed information, see CLR Integration Security.
Stored procedures are routines that cannot be used in scalar expressions. They can return tabular results and messages to the client, invoke data definition language (DDL) and data manipulation language (DML) statements, and return output parameters.
The Common Language Runtime (CLR) is programming that manages the execution of programs written in any of several supported languages, allowing them to share common object-oriented classes written in any of the languages. It is a part of Microsoft's . NET Framework.
As a side note, if you're trying to access temporary tables created with #
, such as #tmp
, you need to also put in SystemDataAccess = SystemDataAccess.Read
. Another way around this would be to use a common table expression to get your data.
I needed to add DataAccess = DataAccess.Read to the function attribute in order to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With