Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modifying a connectionstring makes it invalid ?

Status
Not open for further replies.

Hokkie

MIS
Nov 21, 2001
77
NL
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:
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
 
Not too sure about this part:
Code:
@""C:\Documents and Settings\Marco Hokke\Mijn documenten\Visual Studio Projects\Hoorspelfabriek\HoorspelActeurs\WindowsApplication6\bin\Debug\Hoorspelacteurs.mdb""
Maybe try something like:
Code:
"\"C:\Documents and Settings\Marco Hokke\Mijn documenten\Visual Studio Projects\Hoorspelfabriek\HoorspelActeurs\WindowsApplication6\bin\Debug\Hoorspelacteurs.mdb\""
using the backslash escape character.

Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Hi Hokkie,

Could you please post your connectionstring from your config file please.
 
Hi,

thanks for your replies. I'm a little tight on time right now but I'll get back on Friday after trying Chip's suggestion.

Hokkie
 
I tried Chip's suggestion but it gave me a invalid sequence character error. I'll look into using escape sequences later. For now, here's the connection string I use (this was generated by VS2003):

Code:
Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data source="C:\Documents and Settings\Marco Hokke\Mijn documenten\Visual Studio Projects\Hoorspelfabriek\HoorspelActeurs\WindowsApplication6\bin\Debug\Hoorspelacteurs.mdb";Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider="Microsoft.Jet.OLEDB.4.0";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Extended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"

 
It's supposed to be a single quote I think.. not a double quote.

i.e.
Code:
@"'C:\Documents and Settings\Marco Hokke\Mijn documenten\Visual Studio Projects\Hoorspelfabriek\HoorspelActeurs\WindowsApplication6\bin\Debug\Hoorspelacteurs.mdb'"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top