SQL Server 2008: Exception when excecuting CLR function which tries to access database through a connection -


I want to use the CLR table-value function in SQL Server 2008, which accesses a database from itself One permission exception is found, I am trying to execute the work as the same user under which it was created. If no obvious cause of this problem ..

Here is the function:

  public partial class MyClass {[SqlFunction (DataAccess = DataAccessKind.Read, FillRowMethodName = "Availability_FillRow" , TableDefinition = "B0RID nchar (32)")] public static IEnumerable Fn_SEARCH_Availability (SqlDateTime check, SqlInt32 overnights) {if (checkin.IsNull || overnights.IsNull) {return null; } List & lt; ResultRoom & gt; Rooms area list = new list & lt; ResultRoom & gt; (); (SqlConnection conn = Using new SqlConnection ("Data Source = MachineName; Initial Catalog = DBNAE; Integrated Security = True")) {conn.Open (); } Return Room Registry; }}  

There is no exception

  occurred during a .NET Framework error in the user-defined routine or aggregate "Fn_SEARCH_Availability" Execution: System.Security . SecurityException: Type I 'SystemkDatakSqlClientkSqlClientPermission, SystemkData, Version = 2.0.0.0, Culture = neutral, failed to request permission PublicKeyToken = b77a5c561934e089'. System.Security.SecurityException: System.Security.CodeAccessSecurityEngine.Check (commodity demand, StackCrawlMark & ​​amp; stackMark, Boolean isPermSet) on (on System.Security.PermissionSet.Demand) on System.Data.Common.DbConnectionOptions.DemandPermission () On system System.Data.SqlClient.SqlConnectionFactory.PermissionDemand on System.Data.ProviderBase.DbConnectionClosed.OpenConnection (DbConnection External Connection, DbConnectionFactory Connection Faner) on System.Data.SqlClient.SqlConnection.Open Data.SqlClient.SqlConnection.PermissionDemand () () StoredProcedures .Fn_SEARCH_Availability (SqlDateTime check, SqlInt32 overnights) on  

Maybe try changing the Installs the connection to use

  using  

(SQL Connection connection = New SQL Connection ("Connection Connection = True; "))

Which tells CLR to use the current SQL connecti

My guess is why your failure is that by specifying integrated security this SQL Server service account will use the credentials.

More information on this

/ div>

Comments