Hello all...
I set a key in the registry with a name as Database, the Value consists of a Database name "PBC_DB.mdb"
My hopes are to use the key in my program (I am using vb6) to find the database; in the connection string rather than having it read ex:
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database\PBC_DB.mdb;Jet OLEDB:Database Password=ecscards"
(bolded part is what I want to replace)
instead of it looking at a specific path I need it to read from the registry...Any ideas??

Thanks much!
Kudos!

you use getsetting function to read the value from registry and then check whether a database with the specified value does exist or not. depending on the result u can execute actions. u need to store the database name along with its fullpath. use this code :-

'to store the dbname with path in registry
savesetting "project","apps","mydb",app.path & "\Database\PBC_DB.mdb"

'in form_load
dim dbname as string

dbname=getsetting("project","apps","mydb")
if trim(dbname)="" then
exit sub
else
if dir(dbname)<>"" then
'database found.perform some actions
else
'database not found.do some actions
endif
endif

Thank you much!!!

I use the db is various forms in the application. How do I continue this is all forms? What do I replace the connection string in the different forms?
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\Database\PBC_DB.mdb;Jet OLEDB:Database Password=password"
(bolded part is what I want to replace)

rather than doing the same coding u can do this:-
take a .bas module(project->add module->open) and create two procedures there;one is for saving and another is for loading like this -

in the .bas module
for saving purpose
public sub savedbpath(dbpath as string)
savesetting "project","apps","mydb",trim(dbpath)
end sub

where dbpath is the complete path of the database u want to save

for loading purpose
public function loaddb() as string
loaddb=getsetting("project","apps","mydb")
end function

now in a form where u want to call just do this -

for saving
call savedbpath(app.path & "\Database\PBC_DB.mdb")

for loading
dim dbname as string
dbname=loaddb()
if trim(dbname)="" then
exit sub
else
if dir(dbname)<>"" then
'dbpath valid
else
'dbpath not valid
endif
endif

Hi! Pbroo and chau,
To infix the database path within your program will make that program non-potable. The best way is to create those things during the installation time in the computer where you install your program.
If you are using the registry, well, an uninstall program should delete the db path entries from the registry. One safe way for the beginners is to use a text or an ini file to hold the required values for the connection string during the program installation. I have shown you an example for the sql database. For Aceess the same thing can be used with slight modification.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.