2 Replies - 5232 Views - Last Post: 23 June 2009 - 08:30 AM Rate Topic: -----

#1 dhanavelraj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 15-June 09

How to connect the SQL Database using Application config file

Post icon  Posted 23 June 2009 - 12:45 AM

Hi,
I am new to this development,now i am doing a project,in which having doubt about how to connect the SQL database by using Application config file.
plz help me....
Is This A Good Question/Topic? 0
  • +

Replies To: How to connect the SQL Database using Application config file

#2 dinkar_bhingarde  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-June 09

Re: How to connect the SQL Database using Application config file

Posted 23 June 2009 - 03:47 AM

View Postdhanavelraj, on 22 Jun, 2009 - 11:45 PM, said:

Hi,
I am new to this development,now i am doing a project,in which having doubt about how to connect the SQL database by using Application config file.
plz help me....



add following code in app.config

<connectionStrings>
<add name="WCFHugeDataserver.Properties.Settings.ServerTestConnectionString"
connectionString="Data Source=servername;Initial Catalog=databasename;User ID=sa;Password=password"
providerName="System.Data.SqlClient" />
</connectionStrings>

get connection string in .cs file by using following lin of code

global::WCFHugeDataserver.Properties.Settings.Default.ServerTestConnectionString


Hope this will help u!
Cheers!
Was This Post Helpful? 0
  • +
  • -

#3 masteryee  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 271
  • Joined: 16-May 09

Re: How to connect the SQL Database using Application config file

Posted 23 June 2009 - 08:30 AM

Another way to do this is:

using System.Configuration;
...
ConnectionStringSettings connStringObj =
   ConfigurationManager.ConnectionStrings["name"]; // "name" = name of the connection string in the config file.
string connString = connStringObj.ConnectionString;
...



You will need to Add a Reference to your project to the System.configuration component. This can be found under the .NET tab in the "Add Reference" window.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1