Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi i have a doubt, i written the following connection string in app.config file,

HTML
add name="constr" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\sw3\Desktop\Invoicebill.mdb;Persist Security Info=True"


in form1.cs i called the connection string as the following format,

C#
OleDbConnection con=new OleDbConnection(ConfigurationSettings.AppSettings["constr"]);

con.open();


it's showing the following error,

"The ConnectionString property has not been initialized."

how to trouble shoot this problem can you help me?
Posted
Updated 12-Feb-14 1:07am
v2

in your app.config file use this
XML
<configuration>
  <appsettings>
    <add key="constr" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\sw3\Desktop\Invoicebill.mdb;Persist Security Info=True" />   
  </appsettings>
</configuration>

and then in form1.cs
C#
OleDbConnection con=new OleDbConnection(ConfigurationSettings.AppSettings["constr"]);
 
con.open();
 
Share this answer
 
v2
Dear Vivek,

Please find the below code for your Problem.

App.config file

<configuration>
<connectionstrings>
<add name="MSSConStr">
connectionString="Data Source=Sithi-PC;Initial Catalog=mssdb2;User ID=XXXXX;Password=YYYYYYY"
providerName="System.Data.SqlClient" />




var myConnectionString = ConfigurationManager.ConnectionStrings["MSSConStr"].ConnectionString;

Regards,
Praveen Nelge
 
Share this answer
 
C#
<configuration>
 <appsettings>
   <add key="ApplicationTitle" value="Sample Console Application" />
   <add key="ConnectionString">
       value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\sw3\Desktop\Invoicebill.mdb;Persist Security Info=True";Database=Northwind;Integrated
              Security=false;User Id=sa;Password=;" />
</add></appsettings>
</configuration>
 
Share this answer
 
try like this:-
in app.config
XML
<configuration>
<connectionStrings>
<add connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\projecty bashi nawxoyy\Bashi Nawxoyy\Bashi Nawxoyy\db_file.accdb" name="connectionString"/>
</connectionStrings>
</configuration>


and in backend:-
C#
string conString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ToString();
db_con = new OleDbConnection(conString);
 
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