connection string on web.config

Discussion in 'ASP .Net' started by eitan, Jun 4, 2005.

  1. eitan

    eitan Guest

    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 :)
     
    eitan, Jun 4, 2005
    #1
    1. Advertising

  2. eitan

    Joel Leong Guest

    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.

    "eitan" <> wrote in message
    news:...
    > 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 :)
    >
    >
     
    Joel Leong, Jun 4, 2005
    #2
    1. Advertising

  3. eitan

    Eitan Guest

    How can I reference a class in my code.
    Need sample code, please.

    Thanks :)

    "Joel Leong" <> wrote in message
    news:...
    > 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.
    >
    > "eitan" <> wrote in message
    > news:...
    >> 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 :)
    >>
    >>

    >
    >
     
    Eitan, Jun 4, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michelle A.
    Replies:
    0
    Views:
    564
    Michelle A.
    Aug 20, 2003
  2. Replies:
    4
    Views:
    13,611
  3. Replies:
    0
    Views:
    1,553
  4. CSharpner
    Replies:
    0
    Views:
    1,094
    CSharpner
    Apr 9, 2007
  5. Replies:
    3
    Views:
    856
    Samuel R. Neff
    Aug 3, 2007
Loading...

Share This Page