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: 188
  • Last Modified:

HardCoding of DB location in the application to be changed to user specified

I am in the process of making a VB6 application that reads table data from one local DB in Access and writes data to another remote DB on the network. I am using the Package Wizard to give an installable for the users. The problem is that i dont want to hardcode the DB location in the code. It should be specified during installation of the application and the users should be able to specify Username and PWd incase it is on a restircted server on the netwrok.

0
pushp
Asked:
pushp
1 Solution
 
supunrCommented:
you could put the database in the same location as the application and use App.Path option to get the db location.

eg.

Cons DBName = "Dbname.MDB"

Private Sub OpenDB()
    Dim DBFile as String
    Dim ConnectionString as String

    if (right(App.Path,1) = "\") then
        DBFile = App.Path & DBName
    Else
        DBFile = App.Path & "\" & DBName
    End if

   ConectionString = "....;Data Source=" & DBFile
End Sub

Good LUck!
0
 
pushpAuthor Commented:
Can not do that as the DB will be on a server on the network. It is an application that will be installed on maybe 10 15 machines and the Destination DB can only be in one place
0
 
supunrCommented:
OK, if that is the case, then just save the database name is a file in the application directory.  If that file is not found, then prompt the user for the database location.  If the file is found, but the database is not found in the location, then again prompt the user for the database locaiton.... following is the code I use....

' Get the location of the database
' --------------------------------
Private Sub GetDBName()
    Dim location_file As String
   
    location_file = App.Path & "\" & "db_location.txt"
   
    ' check if the dabase location exist in the registry
    If (Dir(location_file) = "") Then  ' location file not found, ask the user
        Load frmCompactDBMsg
        frmCompactDBMsg.Visible = False
        With frmCompactDBMsg.ComDlg
            .Filter = "Program Database (" & DATABASE_NAME & ")|" & DATABASE_NAME
            .FilterIndex = 0
            .InitDir = App.Path
            .DialogTitle = "Find the location of program database"
            .CancelError = True
            On Error Resume Next
            .ShowOpen
            DATABASE_FILE = .FileName
        End With
        Unload frmCompactDBMsg
        ' now save the file name in the location file
        If (DATABASE_FILE <> "") Then
            Open location_file For Output As #1
                Print #1, DATABASE_FILE
            Close #1
        End If
    Else    ' database file found, read the location from the file
        Open location_file For Input As #1
            Line Input #1, DATABASE_FILE
        Close #1
        If (DATABASE_FILE = "" Or Dir(DATABASE_FILE) = "") Then
            MsgBox "Program database is not found in the location:" & vbCrLf & """" & DATABASE_FILE & """" & vbCrLf & vbCrLf & "Please select the database location..."
            Load frmCompactDBMsg
            frmCompactDBMsg.Visible = False
            With frmCompactDBMsg.ComDlg
                .Filter = "Program Database (" & DATABASE_NAME & ")|" & DATABASE_NAME
                .FilterIndex = 0
                .InitDir = App.Path
                .DialogTitle = "Find the location of Program database"
                .CancelError = True
                On Error Resume Next
                .ShowOpen
                DATABASE_FILE = .FileName
            End With
            Unload frmCompactDBMsg
            ' now save the file name in the location file
            If (DATABASE_FILE <> "") Then
                Open location_file For Output As #1
                    Print #1, DATABASE_FILE
                Close #1
            End If
        End If
    End If
End Sub
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
supunrCommented:
Something I forgot to mension is that this code is in a global module called by Main Function.  You also have to add a Form call "frmCompactDBMsg" and add CommonDialogbox control to that form called "ComDlg".  
0
 
manduz_griffusCommented:
upon the first use of your application, prompt the user to set the path of the DB. then save the selected path to the system registry. if then the DB is moved or deleted in the future prompt the user to set another location.

you can do this by setting a field for first use.
if first use then set DB path.
upon each use af the Application detect if the DB path exists.
if DB path doesnt exist then prompt the user to set DB path.

hope this helps!

manduz_griffus
0
 
pushpAuthor Commented:
Can not do that as the DB will be on a server on the network. It is an application that will be installed on maybe 10 15 machines and the Destination DB can only be in one place
0
 
CleanupPingCommented:
pushp:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
DanRollinsCommented:
pushp, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
0
 
YensidModCommented:
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

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