Hi,
Is it good from security point of view to create a separate class for connection and use it? or save the connection string in web.config file... Which is the best method?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ankit NandekarRank #703 · 3.4K reputationPosted May 24, 2011, 12:04 AM EDT
These have some benefits :
Posted May 24, 2011, 12:57 AM EDT
Moreover you can encrypt the connectionstring and you can store it into the configuration files also.
http://www.codeproject.com/KB/aspnet/webconfig.aspx
http://chiragrdarji.wordpress.com/2008/08/11/how-to-encrypt-connection-string-in-webconfig/
Suthish NairRank #92 · 22.8K reputationPosted May 24, 2011, 1:20 AM EDT
The problem with storing connection strings in web.config is, whenever you update the web.config all the sessions get cleared/Killed which results in throwing out the users from web site.
So this can be avoided by using an .xml file for storing user credentials.
Remember to do file encryption/decryption if security is a concern.
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted May 24, 2011, 1:36 AM EDT
As suthish said, .xml file is the very best option to store connection string value. But most of the people store the connection string in web.config file...
Kavita B135 reputationPosted May 24, 2011, 2:59 AM EDT
If we store the connection string in XML file... How to access it? I never tried it before so plzzz help
Posted May 24, 2011, 3:08 AM EDT
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"C:\ConnectionString.xml");
XmlNode xn = xmlDoc.SelectSingleNode("ConnectionString");
connStr = xn.InnerText;
Later you can use the "connStr" variable in your application.
Suthish NairRank #92 · 22.8K reputationPosted May 24, 2011, 3:12 AM EDT
1. xml file (1.xml)..
2. fetch the ConnectionString
Label1.Text = GetConnectionStringKey("ConnectionString")
3. method to read the xml file, Lot of ways to read the xml.
Different ways of reading an XML file
You can store any config settings and later retrieve..
Jiteendra SampathiraoRank #585 · 4.1K reputationPosted May 24, 2011, 3:14 AM EDT
Retrive the values based on