Click here to Skip to main content
15,942,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all
Iam working with an windowsformapplication which consist of almost 45 forms and the database is MS Acess for the ease of Coding I had declared connectionstring as below in every Forms
C#
public partial class LoginForm : Form
   {
    private String connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\NauferTransactionDemoDB.accdb";

       public LoginForm()
       {
           InitializeComponent();
       }}


But now project is almost over and I want to make this connection declared in appconfig so that I can change it easily if I want
Iam new to programming and is facing the problem with the same

i used


HTML
<configuration>
  <connectionstrings>
    <add name="connect">
         connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\NauferTransactionDemoDB.accdb";User Instance=True"
    />
  </add></connectionstrings>
</configuration>


But when i try to call this in Forms like below
String cString = ConfigurationManager.ConnectionStrings["connect"]. connString;
I get Exception at connectionstring

Can any one help

[edit]"Treat my content as plain text..." option disabled - OriginalGriff[/edit]
Posted
Updated 13-Feb-12 9:08am
v3

1 solution

<add name="Name" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\NauferTransactionDemoDB.accdb";User Instance=True" />


http://msdn.microsoft.com/en-us/library/ms254494(v=vs.80).aspx[^]
 
Share this answer
 
v2

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