Results 1 to 8 of 8

Thread: Relative path to mdb file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question Relative path to mdb file

    Is there a way I can specify a relative path to my mdb file instead of an exact path as showing below:

    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\VB Project\FormPractice\Login\Scholarship.mdb"
    I have tried: Data Source=C:\...\Scholarship.mdb but this doesn't work. I also tried this: Data Source=Data\Scholarship.mdb but same thing happened. I receive an error.

    Many thanks in advance!

    Chong

  2. #2
    Addicted Member
    Join Date
    Aug 1999
    Posts
    164
    You can use your Application.StartupPath variable to create an absolute path based on relative information, etc. But you have to use an absolute path.
    -Shurijo

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This would be more practical :
    VB Code:
    1. Private Shared My_Path As String = Application.StartupPath & "\webdb.mdb"
    2. Private Shared My_Password As String = "YOUR PASSWORD"
    3.  
    4. Private Shared My_Connection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyPath & ";Jet OLEDB:Database Password=" & MyPassword)

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question

    Thanks for helping me. However, this is the error I got after I follow your suggestion.

    An unhandled exception of type ‘System.Data.OleDb.OleDbExcetion’ occurred in system.data.dll
    I have always received this error if I did not put an exact path to the data source. I did a step by step debug and by using the application.startup variable, I was able see the correct path but after the cn.open(), the application just crashed with the above error.

    Chong

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Check database name , path or post some of your code to see what's wrong ?

  6. #6
    Lively Member
    Join Date
    Nov 2002
    Location
    Malaysia
    Posts
    124

    Catch Exception

    Originally posted by Chong
    Thanks for helping me. However, this is the error I got after I follow your suggestion.



    I have always received this error if I did not put an exact path to the data source. I did a step by step debug and by using the application.startup variable, I was able see the correct path but after the cn.open(), the application just crashed with the above error.

    Chong

    VB Code:
    1. Try
    2.     cn.open()
    3. Catch dbException as System.Data.OleDb.OleDbException
    4.     Messagebox.show(dbException.message)
    5. End Try

    use above code to show what was the error occured

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    Thanks! It's working now. I didn't know that the application.startup starts in the bin folder. I put the mdb files in there and it's working now.

    Again, thanks!

    Chong

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    errors regarding paths in ado.net can't be shown when using try...catch structure .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width