Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I'm using Entity Framework in my project. Connection string for connecting database is available in web.config file like
XML
<add name="DEMOEntities" connectionString="metadata=res://*/DEMO.csdl|res://*/DEMO.ssdl|res://*/DEMO.msl;provider=System.Data.SqlClient;provider connection string="data source=SQLSERVERNAME;initial catalog=demo_dev;user id=demo_dev;password=demo_dev;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />


Simply I wanna hide username and password using encryption or any other techinique,
Please do needful

Thanks & Regards
Amol
Posted
Updated 23-Dec-19 22:16pm

Perhaps this MSDN entry[^] can help.
 
Share this answer
 
Hi, I have been working a project to SQL CE, we had the necessity to encrypt the password and apply the following solution, I hope this approach work for you:

C#
//get the encrypted connection string
var strConnectionString = ConfigurationManager.ConnectionStrings["EntitiesTest"].ConnectionString;

//Split the connetion string with "=" separator
string[] staConnectionString = strConnectionString.Split('=');

//Decrypted password and assigned it to variable
var strDecrypted = WrapperClass.Utilities.Decrypt(staConnectionString[5].Replace("\"",""));

//Build a new connection string with the information
var strConnectionString2 = string.Format("{0}={1}={2}", staConnectionString[3].Replace("\"", ""), staConnectionString[4], staConnectionString[5].Replace("\"", ""));

//Assign the new connection string in Database connection string
Database.Connection.ConnectionString = strConnectionString2;
 
Share this answer
 

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



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