简体   繁体   English

MySQL连接代码需要修复。 我走到了尽头

[英]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,用户名和密码。

mysql_error.Message

You can't connect to MySQL using SqlConnection class. 您无法使用SqlConnection类连接到MySQL It is designed to connect to MS SQL Server. 它旨在连接到MS SQL Server。 Try use this 试试这个吧

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.

相关问题 更新密码而不进行散列,并在MYSQL中出现死胡同 - Updated Password Without Hashing it and Occurred a Dead end in MYSQL 对于 Flask 应用程序中的第二个请求,是否有解决“MySQL 连接不可用”的解决方案? - Is there a solution in fixing 'MySQL connection not available' for very second request in Flask application? Sql 易受攻击的脚本需要修复 - Sql vulnerable script needs fixing 如何检查与MySQL db的连接没有失效,并避免不必要的(关闭并)重新创建连接? - How to check a connection to MySQL db is not dead, and avoid unnecessarily (close and) re-create connection? 如果仅使用英语,是否应该将mysql转换为UTF-8? 如果mysql和php为UTF-8,则需要更改哪些php代码? - Should I convert mysql to UTF-8 if only using english? If mysql and php are UTF-8 what php code needs to be changed? mysql 已死,但 subsys 已锁定 - mysql is dead but subsys locked node-mysql 连接结束或销毁不工作 - node-mysql connection end or destroy not working 如何结束mysql连接而不让它在NodeJS中挂起? - How to end a mysql connection and not let it hang in NodeJS? 备份死的MySQL服务器 - Backup dead MySQL server 每个连接关闭后我是否应该执行mysql-library-end() - Should I execute mysql-library-end() after each connection close
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM