connection string on web.config

  • Thread starter Thread starter eitan
  • Start date Start date
E

eitan

Hello,
I put the following code in web.config

<appSettings>

<add key="ConnectionString"

value='PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
Source=Server.MapPath("/db/mydb.mdb")' />

</appSettings>



The code is wrong.

In vb code, I wanted to do :

conMain.ConnectionString =
ConfigurationSettings.AppSettings("ConnectionString")

(where conMain is oleDB.oleConnection)

but the connectionString was wrong.

So, what I did is :

conMain.ConnectionString = "provider = microsoft.jet.oledb.4.0; data source
= " _

& Server.MapPath("./db/mydb.mdb")


Can I do it otherwise ?

Can I just put in vbscript/javascript (server code),

and reference the code at the aspx page ?

How can I do that ?



Thanks :)
 
You can't do that.

The easiest way is remove the server.mappath function,
create a class with static method, inside this method, get the 'source'
token and then
use server.mappath to change the /db/mydb.mdb. Return the new connection
string from this method.
So everytime you need connectionstring, just call the static method.
 
Back
Top