Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 27-Jan-13 22:38pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

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



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100