[英]MySQL Connection code needs fixing. I hit a dead end
I'm currently working on a custom admin panel for a DayZ server, which will run on a local computer & connect to a remote database. 我目前正在为DayZ服务器开发自定义管理面板,该服务器将在本地计算机上运行并连接到远程数据库。 I've Google'd more than ever, but I've hit a dead end.
我比以往任何时候都谷歌了,但我已经走到了尽头。 I can't seem to find a fix for this code which I've found & been told that it should work.
我似乎找不到这个代码的修复程序,我已经找到并且被告知它应该可以工作。
Public Function sqlConnect(ByVal server, port, instance, uname, pword) As Boolean
Dim connection As SqlConnection
connection = New SqlConnection()
connection.ConnectionString = "Server=" & server & port & "; Uid=" & uname & "; Pwd=" & pword & "; Database=***;"
Try
connection.Open()
MessageBox.Show("Connection Opened Successfully")
Return True
connection.Close()
Catch mysql_error As SqlException
MessageBox.Show("Error Connecting to Database: " & mysql_error.Message)
Return False
Finally
connection.Dispose()
End Try
End Function
If anyone here could help me out in finding the solution as to how I can get onto that MySQL server, you'ld be forever in my debt. 如果这里有人可以帮助我找到解决方案,我将如何进入MySQL服务器,你将永远负债累累。
Notes: I'm using VS 2012 express, programming this exclusively in VB.NET, because it's quite a big project (for me) and it's the language I know best. 注意:我正在使用VS 2012 express,只在VB.NET中编程,因为它是一个非常大的项目(对我来说),它是我最熟悉的语言。 Any add-ons required can be downloaded, as long as other users won't have to download it aswell.
只要其他用户不必下载它,也可以下载所需的任何附加组件。
I've never used a MySQL database before, so I might just be doing something completely wrong. 我之前从未使用过MySQL数据库,所以我可能只是做了一些完全错误的事情。
EDIT: The information that is given beforehand contains: server ip, port, database ID, username & password. 编辑:事先给出的信息包含:服务器IP,端口,数据库ID,用户名和密码。
Found it, this code works perfectly: 找到它,这段代码完美无缺:
Public Function sqlConnect(ByVal server, port, instance, uname, pword) As Boolean
Dim connection As MySqlConnection
connection = New MySqlConnection()
connection.ConnectionString = "Host=" & server & ";port=" & port & _
";user=" & uname & ";password=" & pword & ";"
Try
connection.Open()
MessageBox.Show("Connection Opened Successfully")
Return True
connection.Close()
Catch mysql_error As MySqlException
MessageBox.Show("Error Connecting to Database: " & mysql_error.Message)
Return False
Finally
connection.Dispose()
End Try
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.