469,579 Members | 1,899 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Relative paths in VB

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
Nov 20 '05 #1
8 3255
* "Daniel Serrano" <an*******@discussions.microsoft.com> scripsit:
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/groups?selm=uqB7aj0zDHA.3416%40tk2msftngp13.phx.gb l>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
"Daniel Serrano" <an*******@discussions.microsoft.com> schrieb
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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Cor
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/vbr...q/#installvdir
I hope this helps a little bit?

Cor
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.

Nov 20 '05 #4
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"

"Cor" <no*@non.com> wrote in message
news:uQ**************@TK2MSFTNGP09.phx.gbl...
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/vbr...q/#installvdir
I hope this helps a little bit?

Cor
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.


Nov 20 '05 #5
Cor
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
Nov 20 '05 #6
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.
"Cor" <no*@non.com> wrote in message
news:OM**************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #7
Cor
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

Nov 20 '05 #8
for future use.......

http://www.kjmsolutions.com/flexible...tionstring.htm
"scorpion53061" <Its the end of the world as we know it@here.com> wrote in
message news:uD**************@TK2MSFTNGP11.phx.gbl...
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"

"Cor" <no*@non.com> wrote in message
news:uQ**************@TK2MSFTNGP09.phx.gbl...
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/vbr...q/#installvdir
I hope this helps a little bit?

Cor
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.



Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Doug | last post: by
7 posts views Thread by mark | last post: by
2 posts views Thread by Joe | last post: by
2 posts views Thread by Alex | last post: by
8 posts views Thread by JJ | last post: by
15 posts views Thread by Lars Eighner | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.