我为我的vb项目创建了一个安装程序。它试图将它安装到我的工作PC并且它工作。然后我将它安装到另一台PC上。它已成功安装,但当我尝试运行它时,系统无法连接到我的数据库。它给了我一个错误:
Can't connect to MySQL -unable to connect to any of the specified mysql hosts
我只创建了一个安装程序,其中包含.exe
和数据库,没有别的。
我是否遗漏了vb.net application
mysql database
在其他PC上顺利运行所需的一些要求或其他应用程序?它是什么?
导致问题的原因是什么?
提前感谢!
答案 0 :(得分:0)
正如我们在上面的评论中所讨论的,使用'localhost'连接到MySQL服务器只能在安装服务器的机器上运行。要从其他计算机连接到您的服务器,允许用户输入服务器的路径并将该信息保存在MySQL数据库之外,这样用户就不必每次都输入它。
首先,如果您还没有属性文件,请通过在项目的bin文件夹中保存.txt文件来创建一个属性文件。 (对我来说,那是Documents \ Visual Studio 2013 \ Projects [项目名称] [项目名称] \ bin \ Release - 路径可能与您相同或相似。)如果这是您要存储的全部内容,只需键入{{ 1}}在txt文件中并将其另存为properties.txt。如果您仍在调试,请将文件复制到bin的Debug文件夹中。
localhost
将上述代码放在项目中的适当位置,以便在尝试连接到数据库之前执行一次。然后将现有代码连接到您的数据库,在此代码中将“localhost”替换为“serverPath”(当然连接到您的SQL命令中):
Imports System.IO
Dim filePath as String = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) & "\properties.txt"
Dim serverPath as String
Using fReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(filePath)
fReader.TextFieldType = FileIO.FieldType.Delimited
fReader.SetDelimiters(",")
Dim currentRow As String()
While Not fReader.EndOfData
Try
currentRow = fReader.ReadFields()
'If you have other values stored here, check that length of currentRow matches the number of properties you expect to import and import anything else you have saved here
serverPath = currentRow(0) 'or whichever place you save it in your file
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
'File is not formatted as expected
End Try
End While
End Using
给那个旋转。还有其他方法可以阅读和编写您可以查看的文件,但这应该可以满足您的所有需求。