Click here to Skip to main content
11,493,233 members (60,033 online)
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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 393
1 Maciej Los 286
2 F-ES Sitecore 224
3 KarstenK 210
4 CPallini 208
0 Sergey Alexandrovich Kryukov 10,132
1 OriginalGriff 8,630
2 Sascha Lefèvre 3,624
3 Maciej Los 3,392
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2015
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