Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
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 regPerm As RegistryPermission
            'regPerm = New RegistryPermission(RegistryPermissionAccess.Read, "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\WinApp\SmartShopSTV2")
            'regPerm.SetPathList(RegistryPermissionAccess.Read, "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\WinApp\SmartShopSTV2")
            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:
VB
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
Posted
Updated 16-Jun-14 3:24am
v4

1 solution

 
Share this answer
 
Comments
mahesh_deshmane 16-Jun-14 10:12am    
Hey Buddy thanks for u response,

I tried attached link solution but getting same error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900