title: SqlFunction fails to open context connection despite DataAccessKind.Read present
body: <p>I've got a SqlServer project with a very simple test for a Table-Valued-Function:-</p>
  
  <pre><code>[SqlFunction(TableDefinition = "forename nvarchar(50)", FillRowMethodName = "TestFillRow", DataAccess = DataAccessKind.Read)]
  public static IEnumerable TestConn(int ID)
  {
      using (SqlConnection con = new SqlConnection("context connection=true"))
      {
          //con.Open();
          yield return "Anthony";
      }
  }
  
  public static void TestFillRow(object obj, out string forename)
  {
      forename = (string)obj;
  }
  </code></pre>
  
  <p>Note the Open on the connection is currently commented out.  Once deployed I can execute like this in SQL:-</p>
  
  <pre><code>SELECT * FROM [dbo].[TestConn](1)
  </code></pre>
  
  <p>All works fine.</p>
  
  <p>Now I uncomment the <code>con.open()</code> and it fails with:-</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>I don't see what the problem is, the TestConn function has got <code>DataAccessKind.Read</code>.</p>
  
  <p>Anyone know of any other reasons for getting this error?</p>