1

In my application i have a access database with a list of customers, this database is imported in my project. A combobox datasource is set to display all the customers.

I also created a form so the user can change some settings and locations of certain files. for this i use the this.properties.settings.KlantenDB() the string is created and will save the path to the customer database.

How can i change the current Access database connection string so it will use the KlantenDB path?

enter image description here

1 Answer 1

1

Call

AppDomain.CurrentDomain.SetData("DataDirectory", path);

and provide the full path to the data files.

The KlantenConnectionString should provide the full connection string. That |DataDirectory| part of the connection string will be replaced with the value you set using the above call to SetData.

In your case, the following call should work

AppDomain.CurrentDomain.SetData("DataDirectory", "C:");
Sign up to request clarification or add additional context in comments.

2 Comments

This works great. Ended up with this. string klantenDBstring = Properties.Settings.Default.KlantenDB; int index = klantenDBstring.LastIndexOf(@"\"); if (index > 0) klantenDBstring = klantenDBstring.Substring(0, index); AppDomain.CurrentDomain.SetData("DataDirectory", klantenDBstring);
Just for the sake of completeness: Never use something like LastIndexOf on path names. There's a Path class with methods you can use: string path = Path.GetDirectoryName(Properties.Settings.Default.KlantenDB);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.