App.config Question?

  • Thread starter Thread starter Debbie Carter
  • Start date Start date
D

Debbie Carter

Is it possible to place this inside of my app.config file and if so would
anyone know how to properly format the "value" string so when I get this
value it comes out the correct way?

<add key="OleDbConnection1.ConnectionString"
value="Provider=Microsoft.Jet.OLEDB.4.0;Data source=" &
Application.StartupPath & "\mydb.mdb";Jet OLEDB:Database Password=pass" />

Thank you
 
One way would be to use some character to indicate the startup path.
For example, you might use the ~ (tilde) character for this purpose.:

value = ...... Data source=~\mydb.mdb .....


Then in the code when you read the value do a string.replace on the ~
and replace it with the app path:

strConn = value.Replace("`",Application.Startuppath)

I'm not sure, but I think web servers use this notation to indicate the
root web.
 
I don't know how you would do that. However, you could do something like:

<add key="OleDbConnection1.ConnectionString"
value="Provider=Microsoft.Jet.OLEDB.4.0;Data source={0}\mydb.mdb";Jet
OLEDB:Database Password=pass" />

and then use the String.Format command to replace the {0} with your value.

Chris
 
That's a good idea, though I wouldn't use a tilde character because that's a
valid character for a filename/path. Maybe a question mark?
 
Back
Top