The hard coded links in the VB6 apps to the Access databases

  • Thread starter anatoly.duzhansky
  • Start date
A

anatoly.duzhansky

Our application is written in VB6 with Access (2003) databases used as
a back end.
(I'm new in VB6 and VB in general... I'm a PowerBuilder developer.)
Unfortunately the links to the databases are hard coded, refer to
below:
Set PhoneirDB = Workspaces(0).OpenDatabase("r:\GutsShared\data
\agmaster.MDB")

We need to get reed from the old sever and the hard coded links in our
existing
VB application. The plan is:
1. Create INI file and install it on application server (where exe is
resigned).
Specify links to the Access database in the INI file, Example: \
\ltcbuild01\GUTS_SHARE\First.mdb
2. Modify VB code utilizing VB6 functions to be able to read from the
INI file.

Please provide me with code examples about how it can be done or how
it's done
in your applications... another words, how it can be coded in INI file
and
front end application developed in VB6?

Thanks a lot,
Anatoly
 
A

Albert D. Kallal

That is a good desing approach. In fact, my access applicons check a
filename.ini text file...open the contexnts, and the use the path name in
the .ini file for the data.
Our application is written in VB6 with Access (2003) databases used as
a back end.
(I'm new in VB6 and VB in general... I'm a PowerBuilder developer.)
Unfortunately the links to the databases are hard coded, refer to
below:
Set PhoneirDB = Workspaces(0).OpenDatabase("r:\GutsShared\data
\agmaster.MDB")

You could/should ask this question in a vb6 newgroups. It sounds like you
NOT using ms-acces code, but VB6 code.

However, ms-access and vb6 share the SAME coding lanauge.

(so, when you learn ms-access coding, you actually learn the vb6 syntax, but
the forms and object models are VERY differnt. So, same lanauge...but,
differnt objects for forms etc.).

We need to get reed from the old sever and the hard coded links in our
existing
VB application. The plan is:
1. Create INI file and install it on application server (where exe is
resigned).

Ok, here how you open/read the 1st line of the .ini file from Vb6.

Dim strFile As String
Dim intFile As Integer

strFile = App.Path & "\DataPath.ini"
intFile = FreeFile()

Open strFile For Input As intFile
Line Input #intFile, gblDataPath
Close intFile

MsgBox gblDataPath

Thus, in code you go:

Set PhoneirDB = Workspaces(0).OpenDatabase(gblDataPath)

Not a big deal...but, technically you talking about a vb6 question, and not
really an access question.

In MS access the links to tables are actually saved for us in our table
definitions. What we do is we set the all the table links in our application
to the backend file. What this means as a general design philosophy in MS
access we can change our back end file at will without having to write any
code (when you run a split database). So, it's pretty much standard fare as
to how the whole system works and we can re-link to any database without
code. This of course is not that same case in VB6 as your example shows.

However, I'm curious that you *specifically* mention access 2003? Because if
your application is written in VB6. then in fact you should not need ANY
version of MS access installed at all. However if you do in fact need/use MS
access, then in addition to the VB6 side of things connecting to the back
end, you'll have to address any code or parts of MS access that also needs
these links (thus, if you have a hybrid application (vb6 + ms access), then
my comments about setting up the correct table links *in ms-access* may very
well apply to you.
 
T

Tony Toews [MVP]

1. Create INI file and install it on application server (where exe is
resigned).
Specify links to the Access database in the INI file, Example: \
\ltcbuild01\GUTS_SHARE\First.mdb

Excellent idea. I use INI files for my Auto FE Updater.
2. Modify VB code utilizing VB6 functions to be able to read from the
INI file.

However I'll disagree with Albert somewhat. If your INI file gets
longer than a few lines it's easier to use the API calls. Search at
vbnet.mvps.org for INI files for all the code you could possible.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
A

anatoly.duzhansky

That is a good desing approach. In fact, my access applicons check a
filename.ini text file...open the contexnts, and the use the path name in
the .ini file for the data.


You could/should ask this question in a vb6 newgroups. It sounds like you
NOT using ms-acces code, but VB6 code.

However, ms-access and vb6 share the SAME coding lanauge.

(so, when you learn ms-access coding, you actually learn the vb6 syntax, but
the forms and object models are VERY differnt. So, same lanauge...but,
differnt objects for forms etc.).


Ok, here how you open/read the 1st line of the .ini file from Vb6.

Dim strFile As String
Dim intFile As Integer

strFile = App.Path & "\DataPath.ini"
intFile = FreeFile()

Open strFile For Input As intFile
Line Input #intFile, gblDataPath
Close intFile

MsgBox gblDataPath

Thus, in code you go:

Set PhoneirDB = Workspaces(0).OpenDatabase(gblDataPath)

Not a big deal...but, technically you talking about a vb6 question, and not
really an access question.

In MS access the links to tables are actually saved for us in our table
definitions. What we do is we set the all the table links in our application
to the backend file. What this means as a general design philosophy in MS
access we can change our back end file at will without having to write any
code (when you run a split database). So, it's pretty much standard fare as
to how the whole system works and we can re-link to any database without
code. This of course is not that same case in VB6 as your example shows.

However, I'm curious that you *specifically* mention access 2003? Because if
your application is written in VB6. then in fact you should not need ANY
version of MS access installed at all. However if you do in fact need/use MS
access, then in addition to the VB6 side of things connecting to the back
end, you'll have to address any code or parts of MS access that also needs
these links (thus, if you have a hybrid application (vb6 + ms access), then
my comments about setting up the correct table links *in ms-access* may very
well apply to you.

Thank you Albert for the code example, I'm still going to implement
the Ini file plan.
Please send me an example of code in Ini file. (How the links to
databases should be referenced? What will be correct syntax?)
Is it like this? I'm giving an example below:

;link to the access db
[Document Root Folder]
location=\\pbosb1111\Apps\First.mdb
 
A

Albert D. Kallal

Thank you Albert for the code example, I'm still going to implement
the Ini file plan.
Please send me an example of code in Ini file.

The example code I posted will work just fine if you ONLY store the path
name in the .ini file

eg:

c:\mydtata\
(How the links to
databases should be referenced? What will be correct syntax?)

The syntax is exactly as I posted. The example code posted was in fact vb6
code.

Is it like this? I'm giving an example below:

;link to the access db
[Document Root Folder]
location=\\pbosb1111\Apps\First.mdb

No. The example code simply opened up a text file called datapath.ini. It is
assumed that the 1st line of the file is the path name (there is no tags, or
stuff like [root folder] heading. It is a plane Jane text file WITH ONE line
of text. That 1st line of text is the path name. So, for above, we have:

\\pbosb1111\Apps\First.mdb

I suppose you could use datapath.txt name for this text file. The file name
don't really matter, the fact of the matter is we simply need a text file to
store the path name you talked about.

There is NO additional code needed other then what I posted. The format of
the datapath.ini was not really in ".ini" format, but simply text on the
first line. I guess for confusion sake, we probably should just using

datapath.txt for the file name.

So, just put in the path name + file name to the back end in the above...and
then use that sample code to read the path name from the 1st line of that
text file.

I don't really see the need to use a real .ini file here, but a text file
with the path name should suffice.

If you *really* do want to use a .ini file format, then Tony's response was
EXACTLY for that reason, and he gave links with code that could read/write a
real .ini file. (but, this begs the question do we really need such a .ini
file with only one line of text in it with the back end path name???).
However, if you do want code to actually read/write a .ini file...then see
Tony's post.

There is little reason to use *real* .ini file format....just store the path
name in a text file as per my example....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top