Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
im working in windows application in C#..i want a simple demo project of hpw to connect the windows application to sql server 2005 using app.config file..
Posted

I googled it and got back 18.4 MILLION results.

Results for ".net connect to sql server"[^]

Google reveals all.
 
Share this answer
 
If you need help on storing connection strings in app.config, see here[^].
 
Share this answer
 
In VS, look at the Solution Explorer.
Under your poject, open the "Properties" branch.
Double click "Settings.settings"
Add a user string called "ConnectionString"
Close and save the settings.

In your code:
string conStr = Properties.Settings.Default.ConnectionString;
using (SqlConnection con = new SqlConnection(strCon))
   {
   using (SqlCommand com = new SqlCommand("SELECT * from MyTable", con))
      {
      SqlDataReader r = com.ExecuteQuery();
      while (r.Read())
         {
         ....
         }
      }
   }

When you change it, and want to save:
Properties.Settings.Default.ConnectionString = 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