Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends

I want to connect with SQL by using config file in C# window form . but i can not use configurationManager. Can u all please suggest me any other way to connect becaue i need sql connection in one place and then want to use it from many place.

thanks
Posted

1 solution

Store the connection string in your settings file, or in a datafile in the User Data folder (see here for how to use that: Where should I store my data?[^])

To use the settings file, just open your project in the Solution Explorer, open the "Properties" branch, and double click on "Settings.Settings"
Give a new string a name "DatabaseConnection", set it as "string", "user", and set a sensible default (the connection string to your SQL instance)
and save and close the page.
Then when you want to use it:
C#
string conStr = Properties.Settings.Default.DatabaseConnection;

To save a new value:
C#
Properties.Settings.Default.DatabaseConnection = conStr;
Properties.Settings.Default.Save();
 
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