Page 1 of 1
decrypting database.config
Posted: Thu Nov 12, 2009 10:44 pm
by mike92117
I have several console applications that I'm developing to do various tasks. My usual approach to this is to read the web.config and get the conn string, that way when and if it changes, it won't break my existing console applications. My console apps have a configuration value of the file to read to get the conn string.
I want to do the same with my ac store, i.e., have my console applications read the database.config file in app_data. However, it is encrypted and I want to know what I need to do to decrypt it.
Re: decrypting database.config
Posted: Fri Nov 13, 2009 6:35 am
by jmestep
You could store the connection string unencrypted in the global.asax file if you can code against it from there. Here's an example of doing it in one way, but you could put the whole connection string in as a string.
Found by Googling:
Code: Select all
Global.asax.cs
protected void Application_Start(Object sender, EventArgs e)
{
Application["DbUser"]="dbUser";
Application["DbUserPass"]="myPass";
Application["DbName"]="coolDB";
Application["DbServer"]="my.office.db.server";
string myConnString = "Data Source=" +
Application["DbServer"] + ";Initial Catalog=" +
Application["DbName"] + ";User ID=" +
Application["DbUser"] + ";Password=" +
Application["DbUserPass"];
Application["ConnString"] = myConnString;
}
You could use Application["ConnString"]= (whole connection string here)
Re: decrypting database.config
Posted: Fri Nov 13, 2009 6:37 am
by mazhar
Give a try and make use of CommerceBuilder.Utility.EncryptionHelper.DecryptAES method by providing it the ciphered string.
Re: decrypting database.config
Posted: Fri Nov 13, 2009 6:03 pm
by mike92117
Thank you for your answers.
I actually found a super simple and very elegant way to accomplish this:
Code: Select all
VirtualDirectoryMapping vdm = new VirtualDirectoryMapping(@"C:\www\myAbleCommerceSite", true);
WebConfigurationFileMap wcfm = new WebConfigurationFileMap();
wcfm.VirtualDirectories.Add("/", vdm);
Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");
string connStr = config.ConnectionStrings.ConnectionStrings["AbleCommerce"].ConnectionString;