Results 1 to 8 of 8

Thread: Relative path for ADO to connect to a MS Access DB (VB6.0)

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2008
    Location
    Mem Martins (Sintra, Lisboa), Portugal
    Posts
    6

    Relative path for ADO to connect to a MS Access DB (VB6.0)

    Hi,
    I'm working on a VB 6.0 application to access a MS Access database, and I need to use a relative path to connect to the BD, once it's suppose for it to work in different computers... And, while with an absolute path, it works perfectly, whenever I try a realtive path, there's always something wrong... And I've already try many ways:

    First, I tried this:


    "Provider=Microsoft.Jet.OLEDB.4.0; Data Source='..\Calendário de Eventos.mdb';"

    Then, this:

    "Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & Application.StartupPath & "\Calendário de Eventos.mdb';"

    I've also tried this:


    Private Sub Form_Load()
    Adodc1.ConnectionString =
    "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & app.path & "\Calendário de Eventos.mdb;"
    Adodc1.RecordSource = "Select * From Avaliacoes"
    Adodc1.Refresh
    End Sub

    And this (yeah, i know it's getting annoying...):


    m_DBConnection.ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Persist Security Info=False;" & "Data Source=" & calendario_de_eventos.mdb
    m_DBConnection.Open

    (yeah, I now changed the filename of my DB, once spaces and ´ could generate problems, but the errors persist)


    And also this one, similar to the previous:

    m_DBConnection.Open "Provider=Microsoft.Jet.OLEDB.3.51;" & "Persist Security Info=False;" & "Data Source=" & calendario_de_eventos.mdb


    (NOTES: Calendário de Eventos.mdb, as well as calendario_de_eventos.mdb, are my database names; Avaliacoes is the table from that DB that I want to display, and I'm using DataGrid for this)

    Still, there are errors; currently, the error is this one: the name of the data source hasn't been found and no default controller was specified (my error was in portuguese, so this translation may fail somehow, though I think it's fine)

    So, I wonder what is wrong with my program that makes impossible the use of relative paths? is there any tip you can give me? I would so appreciate if got this problem solved!

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Relative path for ADO to connect to a MS Access DB (VB6.0)

    What we usually do in this case is to save the path in a table, txt file, ini file, registry, etc. and one of the first things the project do is to read this saved path

    .Provider="Microsoft.Jet.OLEDB.4.0; Data Source=" & SAVEDPATH & "\Calendario_de_Eventos.mdb"

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Relative path for ADO to connect to a MS Access DB (VB6.0)

    i don't see why you have a problem this works fine for me
    vb Code:
    1. cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    2.       "Data Source=" & App.Path & "\cputemp.mdb;"
    3.     cn.Open
    you sure this is where the database is? and that the user has enough permissions to use in this folder
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2008
    Location
    Mem Martins (Sintra, Lisboa), Portugal
    Posts
    6

    Re: Relative path for ADO to connect to a MS Access DB (VB6.0)

    Quote Originally Posted by westconn1
    i don't see why you have a problem this works fine for me
    vb Code:
    1. cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    2.       "Data Source=" & App.Path & "\cputemp.mdb;"
    3.     cn.Open
    you sure this is where the database is? and that the user has enough permissions to use in this folder

    yes, the database is in the same folder of the VB project; and none of the errors had to do with permissions, I guess, once both the project and the DB were created and edited in my computer, at home (and I'm the only user), and I've made all those tryings in my computer too... but I will have to deliver my work for it to be used in different computers... I believe that your suggestion was supposed to work, I've already tried so many ways, it's odd...
    Anyway, thanks for the reply :)

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Relative path for ADO to connect to a MS Access DB (VB6.0)

    check app.path is returning what you expect, sometimes in the ide it can surprise you
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Relative path for ADO to connect to a MS Access DB (VB6.0)

    Be careful with App.Path for data files except in "try something out" or "quick and dirty" projects.

    When you create a real application for deployment App.Path is a folder under Program Files that most users are not supposed to have full read/write access to. In Vista this is vigorously enforced unless you turn off UAC - which is not something you can ask users to do. I won't repeat the details, we've seen lots of threads on this already.

    But when using Jet it is always safer to build a full pathname to the MDB, TXT, HTM, etc. files for use in connection strings and SQL statements. Relative paths work, but they're going to be relative to the current directory and not App.Path's value. I think because these often coincide people get confused easily.

  7. #7
    Frenzied Member
    Join Date
    Aug 2006
    Location
    India, Punjab, Bhatinda
    Posts
    1,689

    Re: Relative path for ADO to connect to a MS Access DB (VB6.0)

    it's suppose for it to work in different computers
    I believe you have problems with deployment than simply running the project.
    if so try this link

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2008
    Location
    Mem Martins (Sintra, Lisboa), Portugal
    Posts
    6

    Re: Relative path for ADO to connect to a MS Access DB (VB6.0)

    Ok, with a little bit of each suggestion, I managed to use a relative reference. thank you all!!!

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