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....
2 Replies - 4275 Views - Last Post: 23 June 2009 - 08:30 AM
#1
How to connect the SQL Database using Application config file
Posted 23 June 2009 - 12:45 AM
Replies To: How to connect the SQL Database using Application config file
#2
Re: How to connect the SQL Database using Application config file
Posted 23 June 2009 - 03:47 AM
dhanavelraj, 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....
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!
#3
Re: How to connect the SQL Database using Application config file
Posted 23 June 2009 - 08:30 AM
Another way to do this is:
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.
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.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|