Relative path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hai Nguyen

    #1

    Relative path

    Hi All:

    If I want to connect to an Access data base, the aspx page and the database
    are located in the same folder, how would I refere to the database?

    I got an error when refere to an Access database if the string connection
    does not provide absolute path.
    eg:
    OleDbConnection myConnection = new OleDbConnection (
    "PROVIDER=Micro soft.Jet.OLEDB. 4.0;DATA Source=authors. mdb" );
    then I got the following error:

    Exception Details: System.Data.Ole Db.OleDbExcepti on: Could not find file
    'C:\WINNT\syste m32\authors.mdb '.

    even my authors.mdb is not located at C:\WINNT\system 32 folder.

    TIA.

    Hai



  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Relative path

    Hai,

    You can use the MapPath method on the Server property exposed by the
    Page to get the physical path of a file based on the virtual path. So in
    your case, you would pass it the name of page and then it will return the
    full path. If you pass it just ".", it should return the directory, and
    then you can use that to access your database.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - nicholas.paldin o@exisconsultin g.com

    "Hai Nguyen" <hai.hoa@verizo n.net> wrote in message
    news:uiGjHLUfDH A.2408@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Hi All:
    >
    > If I want to connect to an Access data base, the aspx page and the[/color]
    database[color=blue]
    > are located in the same folder, how would I refere to the database?
    >
    > I got an error when refere to an Access database if the string connection
    > does not provide absolute path.
    > eg:
    > OleDbConnection myConnection = new OleDbConnection (
    > "PROVIDER=Micro soft.Jet.OLEDB. 4.0;DATA Source=authors. mdb" );
    > then I got the following error:
    >
    > Exception Details: System.Data.Ole Db.OleDbExcepti on: Could not find[/color]
    file[color=blue]
    > 'C:\WINNT\syste m32\authors.mdb '.
    >
    > even my authors.mdb is not located at C:\WINNT\system 32 folder.
    >
    > TIA.
    >
    > Hai
    >
    >
    >[/color]


    Comment

    Working...