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!
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"
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:
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\cputemp.mdb;"
cn.Open
you sure this is where the database is? and that the user has enough permissions to use in this folder
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:
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\cputemp.mdb;"
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 :)
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
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.
Re: Relative path for ADO to connect to a MS Access DB (VB6.0)
Quote:
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
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!!!