5

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."}

1
  • this is not an issue anymore, I resolved it ! Commented Apr 2, 2013 at 18:22

2 Answers 2

10

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.

Sign up to request clarification or add additional context in comments.

Comments

7

I needed to add DataAccess = DataAccess.Read to the function attribute in order to do that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.