Click here to Skip to main content
11,926,805 members (55,170 online)
Rate this:
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.

Posted 27-Jan-13 22:38pm

1 solution

Rate this: bad
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;

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.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