I'm trying to build a program in C# (visual studio) that has a Database, but it has to go to specific folder that the user picks when running the program for the first time. The link to the folder is stored in a text file. This is all done using a windows form. I want the app.config file to read the text file so it knows where the database is located. My app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="MyProgram.Properties.Settings.DataBaseTestingConnectionString"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\MyProgram\DataBaseTesting.accdb"
providerName="System.Data.OleDb" />
<add name="cn" connectionString="data source=.;initial catalog=NORTHWIND;user id=sa"
providerName="System.Data.OleDb" />
</connectionStrings>
</configuration>
How can i make source be first line with link in text file (location.txt) located in Desktop? instead of E:\MyProgram\DataBaseTesting.accdb
----SOLUTION-17/06/2022--------------------------------------------------------------------------------- Finally figured it out. First had to change App.Config file and change Data Source. Instead of:Data Source=E:\MyProgram\DataBaseTesting.accdb" i had to change it to: Data Source=|DataDirectory|\DataBaseTesting.accdb" Seconddly in c# file i placed this line: AppDomain.CurrentDomain.SetData("DataDirectory", Global.path); Global.path is my global variable that stored the folder location of my database.