Changing database location

BlueJay924

Well-known member
Joined
May 6, 2003
Messages
46
Im using vb.net. How do i go about changing the location of where my access database is stored? For example, i have my database listed in c:/database.mdb. One group of users may be able to change the location to c:/newlocation/database.mdb. How can i alter my code so that it points to the new location without having to re-edit my code everytime i log in?
 
you could create a registry location , then allow the user to set the path for the file through that , eg:
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim reg As Microsoft.Win32.Registry
        Dim key As Microsoft.Win32.RegistryKey = reg.CurrentUser

        Try
            If key.OpenSubKey(Application.ProductName, True) Is Nothing Then
                key.CreateSubKey(Application.ProductName).SetValue("DbLocation", "C:\MyDb.mdb")
            Else
                MessageBox.Show("key exsists!")
                /// dont create it again.
                /// then you can write a new value to it, eg :
                key.OpenSubKey(Application.ProductName, True).SetValue("DbLocation", "C:\newlocation.mdb")

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub
 
locating database location - HELP!!!

Im still confused on how this works. Is there a good tutorial out there that explains how the registry works? Ive never done this before.

Perhaps i need to explain better what im doing. What i have currently done is hard coded the location of where the database is located. Right now i have about five forms and each is calling where i have placed the database.
So if i tried the code above im assuming Id have to delete the registry location and create a new one if the database is moved more than once. Again, im not sure how this is done and when i tried it, it didnt work. however, if this works, how does the five forms get the information in regards to the location of database. Any help would be great!!!
 
Back
Top