connection string on web.config

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 :)
 
J

Joel Leong

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.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top