Click here to Skip to main content
13,199,680 members (53,829 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hi!! i need to implement backup and restore feature in my winform application...

currently i have set the connectionstring in my app.confg file and its working perfectly fine...
i am using Access 2007 for Database.

my app.confg code..

       <add key="connstr" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\items.accdb" />

my problem, is when the user selects a backup file.. the connectionstring path needs to be changed..

eg- suppose the user selects a backup file 'today_back.bak' now, the file name in app.confg should be changed..

    <add key="connstr" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\today_back.accdb" />

how can i do this can someone please help me... :)

Thanks in Advance
Posted 23-Feb-13 3:08am
Kishor Deshpande 23-Feb-13 9:13am
Have a separate key for these two databases named "back" and "items", and a static connection string property, on user selection of "Backup file", change your static connection string property to "back" key.
So it will now point to back up db.
Hope this helps.
Member 7849477 23-Feb-13 9:16am
Thanks for the reply
can you give me an example..
Kishor Deshpande 23-Feb-13 9:17am
That means I'll have to code, dnt worry I'll do it now :) and post it as answer.
Member 7849477 23-Feb-13 9:18am
thanks :-)
Kishor Deshpande 23-Feb-13 11:03am
Refer solution..
savbace 23-Feb-13 9:47am
Take a look here:

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Combo box has two values Live and Backup, on selected index change code is:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
           DataConnection.ConnectionString = ConfigurationManager.ConnectionStrings[comboBox1.SelectedItem.ToString()].ConnectionString;
           label1.Text = DataConnection.ConnectionString;

I'm just printing connection string on my label where as you can use it to communicate with DB as and when required as it is assigned to your DataConnection.ConnectionString property which holds ConnectionString.
Add System.Configuration namespace to use ConfigurationManager class.

My app.config file:
    <add name="Live" connectionstring="LiveDB" />
    <add name="Backup" connectionstring="BackupDB" />

Now my DataConnection class is the class which is communicating with DB based on ConnectionString property value.

class DataConnection
        public static string ConnectionString { get; set; }

Mark this as acceptable answer if it resolves your issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171020.1 | Last Updated 23 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100