在VB.net中创建一个动态的mysql连接字符串

时间:2018-06-11 16:34:09

标签: mysql vb.net

我有一个使用MySql数据库的Windows应用程序。在源代码(conn string)中包含IP地址192.168.***.***后,它在主机和网络上连接正常,但在更改网络或重新启动Windows时,IP地址会更改,应用程序将再次连接。

这是我的代码:

Imports MySql.Data.MySqlClient
Module Connection
Public cnStringP As String

Public Sub HMS_DB()
    Try
        cnStringP = "server=169.254.210.1;user id=Admin;password=162;persistsecurityinfo=True;database=HMS"
        cnStringP = "server=localhost;user id= Admin;password=007006;persistsecurityinfo=True;database=HMS"
        cnStringP = "server=169.254.241.99;user id= Admin;password=007006;persistsecurityinfo=True;database=HMS"
        cnStringP = "server=127.0.0.1;user id= Admin;password=007006;persistsecurityinfo=True;database=HMS "
        cnString = "server=192.168.1.212;user id= Admin;password=007006;persistsecurityinfo=True;database=HMS"
        cnStringP = "server=169.254.210.126;user id=seyarosystems;password=007006;persistsecurityinfo=True;database=HMS"
    Catch ex As MySqlException
        MsgBox(ex.Message, MsgBoxStyle.Critical, "connection error")
        Application.ExitThread()
    End Try
  End Sub
End Module

这是错误消息:

  

错误。无法连接到任何指定的mysql主机。

我尝试在线搜索,但没有找到解决方案。有没有办法让字符串直接从网络读取IP地址而无需用户输入(动态IP地址)?我正在使用LAN连接

0 个答案:

没有答案
相关问题