how to change the location of database file dynamically in another network

Posted by Ahmedsa under C# on 3/28/2017 | Points: 10 | Views : 1936 | Status : [Member] | Replies : 2
I work in windows form application works in c# visual studio 2015 connect to database access 2007
my connection as bellow
 public static string fileName = @"\\\data\accessqr.accdb";
public string connection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source={0}", fileName);

it working without any problem
but if i need to move database access file accessqr.accdb in another network or another place
may be no ip available or no drive D: available so that
how to make connection dynamic to accept any network ?
so that i need my connection dynamic and is suitable to any place
what i do ?


Posted by: Sheonarayan on: 3/28/2017 [Administrator] HonoraryPlatinum | Points: 25

Instead of hard coding the path of the database in C# code, keep it in the app.config file under appSettings and retrieve from there using ConfigurationManager.AppSettings.

To change the database path, just change the appSettings in the web.config. In this way, you will never need to change the code.

Sheo Narayan

Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Opputesel on: 3/31/2017 [Member] Starter | Points: 25

This is all custom work that is usually done by the developers and they know how to complete the tasks in the given time and provide the readers with the so that they can learn what they have learned with difficulty.

Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response