Relative paths in VB

  • Thread starter Thread starter Daniel Serrano
  • Start date Start date
D

Daniel Serrano

Hi, is it possible to use a relative path in a Connection
string to access an Access database in a stand alone
visual basic desktop application. All the examples that I
have seen have absolute paths but my application could be
a lot more flexible if it didn't depend on this.

Thanks,

Daniel Serrano
 
Daniel Serrano said:
Hi, is it possible to use a relative path in a Connection
string to access an Access database in a stand alone
visual basic desktop application. All the examples that I
have seen have absolute paths but my application could be
a lot more flexible if it didn't depend on this.

Relative to what? You can use a relative path but it would be relative to
the current directory, so you would have to set the current directory first.
Both steps lead to an absolute path, so specifying the absolute path when
opening the connection is easier. You can use Sytem.IO.path.combine to build
an absolute path string.
 
* "Daniel Serrano said:
Hi, is it possible to use a relative path in a Connection
string to access an Access database in a stand alone
visual basic desktop application. All the examples that I
have seen have absolute paths but my application could be
a lot more flexible if it didn't depend on this.

Why not get the application's path and concatenate the full path of the
database?

<http://groups.google.com/[email protected]>
 
Hi Daniel,

If you use the wizards, I was always thinking it is imposible, but maybe you
can but I did not see that until now here and I am not using them, so
finding that out has for me a low priority.

But I think that if you do that you can for the same sake not use the wizard
at all.

If you do not use the wizard it is very easy to do.

The resource kit uses samples without the wizard.

http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it

http://msdn.microsoft.com/vbasic/vbrkit/faq/#installvdir
I hope this helps a little bit?

Cor
 
HI Cor and Daniel,

databasepath is the string of the database location. Now all you have to do
is store that location in an XML file and you are all set.

Please let me know if this helps.

Dim sConn As New OleDb.OleDbConnection
sConn.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data Source=" &
databasepath & _
";Password=;Jet OLEDB:Engine T" & _
"ype=5;Jet OLEDB:Global Bulk
Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Je" & _
"t OLEDB:System database=;Jet OLEDB:SFP=False;Extended
Properties=;Mode=Share Den" & _
"y None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System
Database=False;J" & _
"et OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact
Without Replica Re" & _
"pair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False"
 
Hi Scorpion,

Please show us a sample using the OledBdataadapter Wizard from the designer
and than change the connection string.

(With of course less code than that you make a total connection, a dataset,
and a dataadapter.fill)

(For that I need 4 lines)

:-)

Cor
 
Hi Cor,

It is pretty simple really. I am not the best at explaining things
sometimes. If this does not work let me know and I will try again. Others
feel free to jump in if you understand where I am going.

Make your adapter in the wizard and point to a database on your hard drive
and it automatically generates

"OleDbConnection1"

We don't care about that.

All we want to do is change the connection string.

The object is there. We are just modifying the string it is using.

So we address the string in the code. Copying and pasting the code I used
before will reflect the new database location if you have used
"databasepath" as a string.

You can also create a class and use shared properties so you won't have to
do this again throughout the rest of your project.
 
Hi Scorpion,

You are right,

I checked it, I do not know why it never would work in past.
If you do this in the load event while you are using the designer for the
datadapter and for the binding

SqlConnection1.ConnectionString = connectionstring
SqlDataAdapter1.Fill(DataSet11)

It works normal.

I do not know why I never saw this simple sample in this newsgroups
(In past I have asked this question several times in this newsgroup and did
never got an answer. That was the reason I started to make the connections
by hand)

But it is so simple.

Thanks for your persistancy again.

This was always a question for myself, strange I never found it.

Cor
 
Back
Top