Dear Sir/Mam
Please tell me how can i define connection string in my class file.i do not want to describe it in web.config for Database Security.
//SqlConnection mainConnectionString = new SqlConnection();
string str = "server=192.1.1.1;database=db;user id=sa;password=.com;";
SqlConnection mainConnectionString = new SqlConnection(str);
// mainConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
// mainConnectionString.ConnectionString=("server=192.1.1.1;database=db;user id=sa;password=.com;").ToString();
string sam =Convert.ToString( mainConnectionString);
i use all this thing but project not working but if use
// mainConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
ConnectionString from web.config
then its working fine.
please tell me how i solve this problem or any alternative to secure dB USER and password.
or any decrypt or encrypt method use for web.config.


Lalit RaghavRank #1,306 · 1.3K reputationPosted Jun 7, 2015, 11:29 PM EDT
सौरभ माहेश्वरीRank #6,639 · 260 reputationPosted Jun 8, 2015, 12:45 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Jun 8, 2015, 1:19 AM EDT
Nilesh JadavRank #109 · 20.3K reputationPosted Jun 8, 2015, 4:36 AM EDT
Try this -
You can get your Connection String by going to the database (In Server Explorer right-click on you database then select"Properties". You will then see “Connection String” there. Copy it and paste it into the SQL connection field. Yeah! Surely your connection string is quite different from mine, initially it look like this:
Before
C:\Users\Nilesh\Documents\Visual Studio 2010\WebSites\WebSite13\App_Data -- > Remove this
And add this "|DataDirectory|".
After
Sanjay SabariyaRank #2,262 · 623 reputationPosted Jun 8, 2015, 4:43 AM EDT