?
Solved

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

Posted on 2003-03-06
9
Medium Priority
?
186 Views
Last Modified: 2010-05-01
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
Comment
Question by:pushp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 11

Expert Comment

by:supunr
ID: 8085593
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
 

Author Comment

by:pushp
ID: 8085662
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
 
LVL 11

Expert Comment

by:supunr
ID: 8085695
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
Independent Software Vendors: 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!

 
LVL 11

Expert Comment

by:supunr
ID: 8085703
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
 

Expert Comment

by:manduz_griffus
ID: 8086861
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
 

Author Comment

by:pushp
ID: 8089007
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
 

Expert Comment

by:CleanupPing
ID: 8900546
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 9074262
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
 

Accepted Solution

by:
YensidMod earned 0 total points
ID: 9165916
Question is PAQ'd and no points refunded.

YensidMod
Community Support Moderator @Experts Exchange
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question