none
Accessing encrypted connection string in SharePoint web.config problem

    Question

  • I have edited the web.config for my SharePoint iis web application and added the following:

    <connectionStrings>
        <add name="MyConnectionString" connectionString="Data Source=mysqlserver;network library=dbmssocn;Initial Catalog=mydb;User Id=myuser;Password=somepassword;" providerName="System.Data.SqlClient" />
      </connectionStrings>

    From my web part, I can access the connection string like this:

                string lcConnectionString = "";
                System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
                System.Configuration.ConnectionStringSettings connString;
                if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
                {
                    connString = rootWebConfig.ConnectionStrings.ConnectionStrings["MyConnectionString"];
                    if (connString != null)
                        lcConnectionString = connString.ConnectionString;
                }


    Now, I want to encrypt the connection string found in the web.config so I did this:

    aspnet_regiis -pef "connectionStrings" "C:\inetpub\wwwroot\wss\VirtualDirectories\443"

    This works and the appropriate information is encrypted in the web.config file.

    I added the application pool account to have access to decrypt this information like this:

    aspnet_regiis -pa "NetFrameworkConfigurationKey" "mydomain\myapppoolaccount"

    Now, when I access the SharePoint site, I get the following error:

    HTTP 500 Internal Server Error

    I enabled verbose logging in Central Administration and used ULS viewer and found this in the log:

    "Error=The RSA key container could not be opened."

    At this point I am not sure how to proceed.  Is there another account that needs to be assigned to have access using aspnet?

    Since this is a test environment, I added the farm account to have access too but the error still persists.

    Any help is appreciated...




    • Edited by davestech Friday, April 13, 2012 8:40 PM
    Friday, April 13, 2012 8:39 PM

Answers