App.config Question?

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
 
C

Chris Dunaway

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.
 
C

Chris, Master of All Things Insignificant

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
 
D

Don

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top