Hi,
I have a connectionstring in my configfile which points to a local (Access) database. When I initialize my connection, I read the string from the config file. This works fine.
However, I want to change the data source to a database that's in the application folder. I thought I'd do this by replacing the data source value of the connection string to a different path. Read it in first, change what I have to, and then assign it to the .ConnectionString property of the connection object.
I changed the value of the data source in the config file to '[dbp]', then did a replace on that string to change it to a filepath. After that, I assign it to the connection object.
This does NOT work. When debugging, I tried both methods with the same file path, and compared the resulting connectionstring of the connection object. They are identical--no extra characters, and the path is 100% valid.
Can you please help?
Here's the code I use to set the ConnectionString of the connection object (both methods included):
__________________
code is enduring
I have a connectionstring in my configfile which points to a local (Access) database. When I initialize my connection, I read the string from the config file. This works fine.
However, I want to change the data source to a database that's in the application folder. I thought I'd do this by replacing the data source value of the connection string to a different path. Read it in first, change what I have to, and then assign it to the .ConnectionString property of the connection object.
I changed the value of the data source in the config file to '[dbp]', then did a replace on that string to change it to a filepath. After that, I assign it to the connection object.
This does NOT work. When debugging, I tried both methods with the same file path, and compared the resulting connectionstring of the connection object. They are identical--no extra characters, and the path is 100% valid.
Can you please help?
Here's the code I use to set the ConnectionString of the connection object (both methods included):
Code:
appConfig.cfgFile = "HoorspelActeurs.exe.config";
// Get the connectionstring from the config file
string tempConnect = (string) appConfig.GetValue("//appSettings//add[@key='ConnectionString']");
// change the "[dbp]" value to a database path
cnHoorspel.ConnectionString = tempConnect.Replace("[dbp]", @""C:\Documents and Settings\Marco Hokke\Mijn documenten\Visual Studio Projects\Hoorspelfabriek\HoorspelActeurs\WindowsApplication6\bin\Debug\Hoorspelacteurs.mdb"");
// Or comment the line above and uncomment this one if the connectionstring from the config file already contains a valid database path.
//cnHoorspel.ConnectionString = tempConnect;
System.Windows.Forms.MessageBox.Show(cnHoorspel.ConnectionString);
__________________
code is enduring