Dynamically Search for Database

I have a vb6 application that uses a file .dsn to locate the database on the server:

[ODBC]
DRIVER=Driver do Microsoft Access (*.mdb)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=2048
FIL=MS Access
DriverId=25
DefaultDir=\\ServerName\Shared\SomeFolder
DBQ=\\ServerName\Shared\SomeFolder\SomeDatabase.mdb

It has been requested of me to change this or use a different method for locating the database. The reason for the request is because the user wants to be able to avoid errors being thrown if the server changes, etc. The person requesting the change wants to eliminate the "hard coding" so the application won't be dependant upon this directory path. Is it possible to create something in an install package to where it points to the location of the database? Is this possible?
Gary2397Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

g_johnsonCommented:
you don't need to use an ODBC
Using ADO you can use a connection string that can be stored in an INI or CFG file for retrieval by the program.
Then, nothing needs to be hard-coded, but the INI file does need to be maintainable
0
Gary2397Author Commented:
This sounds like what I am looking for. Will this allow the user to specify the location of the database on installation? I don't have any experience with INI files, is there a good tutorial anywhere.
0
JavaRossCommented:
Personally, INI is the "old way". It works fine in simple cases, but for a more extensible solution, XML is better.
You can try this link:

http://msdn.microsoft.com/vbrun/vbfusion/configurationstation/default.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JavaRossCommented:
This link has a more VB6-centric approach.

http://www.informit.com/articles/article.asp?p=25084&seqNum=3
0
JavaRossCommented:
...and if you just want to use an INI, then you'll want to use these Win32 APIs (link to MSDN info included):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getprivateprofilestring.asp

'****************************************************************
'Windows API/Global Declarations for :.INI read/write routines
'****************************************************************

Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
0
JavaRossCommented:
Finally, to extend on the original comment by g_johnson, here's some info on ADO in case you need it. Incidentally, I apologize for the multi-post response. I should have composed my thoughts better before dumping this all on you.

Reference:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdconintroduction.asp?frame=true

Guide:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adosql/adoprg01_1kwv.asp


Hopefully that should get you oriented in the right direction.
0
jimbobmcgeeCommented:
Is the connection string stored on the local machine, as opposed to a network resource?  If so, you could easily store to the registry with:

    SaveSetting("MyApp", "MyKey", "ConnectionString", "{Provider=...}"

    szConnStr = GetSetting("MyApp", "MyKey", "ConnectionString", "this is the default value")

HTH

J.
0
Naveen SwamyYash Infinite Solutions Private LimitedCommented:
basically u need to have a external file or settings from where you need to load the database, this would be a very good option, if given to the user.

Ini is an old aproach
Registry is good but should be used with caution
XML is a good option, thinking future (its pretty easy to, i learnt basics of xml in 2 hours)
0
jimbobmcgeeCommented:
Alternatively, why don't you host your DSN file remotely?  That way, the client app uses the setting to find the DSN and then connects to it; as long as you keep the DSN updated, you can change the database location as much as you want, without affecting the client app and has the advantage that the user does not need to enter the connection string manually (less chance of mistakes) and does not need to know a database username/password.

You could store the DSN location in the registry or a settings file an even allow the user to browse to the DSN using the Common Dialog control.

J.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.