Hey folks i need a little bit of help im not good with Vb as i am just learning so bare with me ^_^..

Ok well im making a program that will connect to my mysql database located on my other computer in a program called navicat im not sure how to make my application connect to the remote datebase.
I need this app so i can send it to serton people so they can make new lines in the database to post news.

If you do not understand what i mean please just tell me and ill try and word it diffrent.
Thanks for your understanding.

8 Years
Discussion Span
Last Post by ProfessorPC

i have set the sql connection info in the registry and when the user installs this on their machine they can change it in a form. ill try explaining the best i can.
when the user opens the program have it check with the load event to make sure the settings are there. if they are not open the server connection form.
Main Form Load:

Dim sRegKey As RegistryKey = Registry.LocalMachine
        sRegKey = sRegKey.OpenSubKey("software\\company name\\program name")
        Dim server As Object = sRegKey.GetValue("Server")
        m_Server = server.ToString
        Dim dRegKey As RegistryKey = Registry.LocalMachine
        dRegKey = dRegKey.OpenSubKey("software\\company name\\program name")
        Dim DB As Object = dRegKey.GetValue("DB")
        m_db = DB.ToString
        Dim uRegKey As RegistryKey = Registry.LocalMachine
        uRegKey = uRegKey.OpenSubKey("software\\company name\\program name")
        Dim UserName As Object = uRegKey.GetValue("UserName")
        m_Username = UserName.ToString
        Dim pRegKey As RegistryKey = Registry.LocalMachine
        pRegKey = pRegKey.OpenSubKey("software\\company name\\program name")
        Dim password As Object = pRegKey.GetValue("Password")
        m_password = password.ToString
        If m_Server = "" Or m_db = "" Or m_Username = "" Or m_password = "" Then
            Dim opt As New options
            opt.MdiParent = Me
            m_ConnectionString = ("Data Source=" + m_Server + ";Initial Catalog=" + m_db + ";User Id=" + m_Username + ";Password=" + m_password + ";")

i had added the m_ConnectionString, m_Server, m_db, m_Username and m_password into a module

Friend m_Server As String
    Friend m_db As String
    Friend m_Username As String
    Friend m_password As String
    Friend m_ConnectionString As String

in the options i inserted the data into the registry like this:

My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\Software\company name\\program name\", "Server", Me.txtipaddy.Text)
            My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\Software\company name\\program name\", "DB", Me.txtdbname.Text)
            My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\Software\company name\\program name\", "UserName", Me.txtusername.Text)
            My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\Software\company name\\program name\", "Password", Me.txtpass.Text)
            MsgBox("Save Complete", MsgBoxStyle.Information, "Saved")

then search for your connection and just change it to m_ConnectionString.

worked well with that program. I'm sure there are better and easier ways to do this. but this one does work.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.