Hi Guys, I am working on Report module on SSRS, for the dynamic connection of database I am using use “Custom Assemblies” in SQL Server.So, I Created Custom Assemblies which is Accessing(reading) the Registry values such as Server name , Database name etc. from registry.
At runtime of report I am getting “Request for the permission of type 'System.Security.Permissions.RegistryPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.” Error
My Custom Assemblies Code:
Imports Microsoft.Win32
Imports System.Security.Permissions.RegistryPermission
Imports System.Security
Imports System.Security.Permissions
<security.permissions.registrypermission(security.permissions.securityaction.assert,> Public Class Initialize
<registrypermission(securityaction.assert)> Public Function BOConnectionString() As String
Try
Dim Servername As String = ""
Dim Dbname As String = ""
Dim UserName As String = ""
Dim password As String = ""
Dim key As RegistryKey
Dim subkey As RegistryKey
key = Registry.CurrentUser
subkey = key.OpenSubKey("Software\VB and VBA Program Settings\WinApp\SmartShopSTV2")
If (Not subkey Is Nothing) Then
Servername = subkey.GetValue("DBServer").ToString()
Dbname = subkey.GetValue("Database").ToString()
UserName = subkey.GetValue("UserID").ToString()
password = DecryptString(subkey.GetValue("WIN32Password").ToString())
End If
BOConnectionString = "Data Source= " + Servername + ";User ID=" + UserName + ";Password=" + password + ";Initial Catalog=" + Dbname
Catch ex As Exception
Return ex.Message
End Try
End Function
End Class
Stack Trace:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at Microsoft.Win32.RegistryKey.CheckSubKeyReadPermission(String subkeyName) at Microsoft.Win32.RegistryKey.CheckOpenSubKeyPermission(String subkeyName, Boolean subKeyWritable) at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable) at Microsoft.Win32.RegistryKey.OpenSubKey(String name) at SSInitializeConStr.Initialize.BOConnectionString()
Inner Exception is Nothing
I have created strong key for Custom Assemblies also added it in GAC
I am Using SQL Server 2008 R2 with Visual Studio 2008 BI Tools. require your immediate help for the same.
Thanks in advance