dataadapter wizard connection string

Discussion in 'ASP .Net' started by Guest, Sep 5, 2004.

  1. Guest

    Guest Guest

    I'm trying to modify the connection string made by the dataadapter wizard to
    a relative path. My current datasource is this:

    ""C:\Inetpub\wwwroot\database\database.mdb""

    How can i change so when its on the server it will look for the directory
    "database" in the root of the virtual directory?


    cheers
     
    Guest, Sep 5, 2004
    #1
    1. Advertisements

  2. Guest

    Greg Burns Guest

    Dim cn As OleDb.OleDbConnection

    cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    Server.MapPath(ConfigurationSettings.AppSettings("path"))) ' -->>>
    c:\inetpub\wwwroot\global\data\project1.mdb

    web.config...

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings>
    <add key="path" value="/global/data/project1.mdb" />
    </appSettings>

    <system.web>
    .... etc

    HTH,
    Greg
     
    Greg Burns, Sep 5, 2004
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    thx for the reply but i'm looking at the "web form designer generated code"
    and have found the oledbdataconnections and just want to modify this. What
    i'm really having problem with is the syntax.

    '
    'OleDbConnection1
    '
    Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial
    Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
    "ocking Mode=0;Data
    Source=""C:\Inetpub\wwwroot\db\database.mdb"";Jet OLEDB:Engine " & _
    "Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System
    database=;Jet OLEDB:S" & _
    "FP=False;persist security info=False;Extended
    Properties=;Mode=Share Deny None;J" & _
    "et OLEDB:Encrypt Database=False;Jet OLEDB:Create System
    Database=False;Jet OLEDB" & _
    ":Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without
    Replica Repair=Fal" & _
    "se;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"


    Data source - i need to change to a relative path like
    server.mappath(/database/database.mdb) but everything i've tried keeps
    bringing up syntax errors.
     
    Guest, Sep 5, 2004
    #3
  4. Guest

    Greg Burns Guest

    Changing the desinger generated code is asking for trouble. The designer
    will just overwrite it again when you least expect it.

    Greg

    'OleDbConnection1
    '
    Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial
    Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
    "ocking Mode=0;Data
    Source=" & Server.MapPath("/db/database.mdb") & ";Jet OLEDB:Engine " & _
    "Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System
    database=;Jet OLEDB:S" & _
    "FP=False;persist security info=False;Extended
    Properties=;Mode=Share Deny None;J" & _
    "et OLEDB:Encrypt Database=False;Jet OLEDB:Create System
    Database=False;Jet OLEDB" & _
    ":Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without
    Replica Repair=Fal" & _
    "se;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
     
    Greg Burns, Sep 5, 2004
    #4
  5. Guest

    Guest Guest

    I realise playing around in generator code is not the smartest move, thus,
    how can I make the dataadapters call a relative path to the database?
     
    Guest, Sep 6, 2004
    #5
  6. Guest

    Greg Burns Guest

    John, I never use the wizards so haven't ran into this problem. My gut
    response is to say you can't with the wizard (without modify its generated
    output, which is BAD), but somebody will just prove me wrong. :^)

    I found this article on google:
    http://tinyurl.com/4uts9

    It shows how to get the wizard generated code to read your web.config for
    the datasource value. This avoids "messing" with the designer code
    manually, but also doesn't answer your question. (In other words, not sure
    how you would get Server.MapPath to act on your web.config value using this
    method).

    Sorry,
    Greg
     
    Greg Burns, Sep 6, 2004
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.