Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

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?
0
Gary2397
Asked:
Gary2397
1 Solution
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now