darma teja

darma teja

  • NA
  • 496
  • 336.8k

Connect database through config file

Jul 21 2012 7:46 AM
Hi,

I want to connect database through configaration file. I am getting error. 

Here is my code:
Configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="databaseconnectionstring" connectionString="i wrote connection string here"/>
    </connectionStrings> 
</configuration>


My code in c# is:



string connStr = ConfigurationManager.ConnectionStrings["databaseconnectionstring"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
con.open();


Thanks

Darma


Answers (10)