我尝试连接到远程 MySQL 服务器,但即使我没有从服务器提取任何数据,服务器响应对象也无法从 dbnull 转换为其他类型。远程服务器是托管者。
Imports Microsoft.VisualBasic
Imports Microsoft.Win32
Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Public Class MySQLConnect
Dim cn As New MySqlConnection("server=myremoteserver; port=myremoteport; user=mydb_user;password=myDbPassword; database=myremoteDb;")
Private cmd As New MySqlCommand
Private cmd As New MySqlCommand
Private dr As MySqlDataReader
If cn.State = ConnectionState.Open Then cn.Close()
cn.Open()
MessageBox.Show("Connected")
Catch xrr As Exception
MessageBox.Show(Err.Description, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Sub
End Class
但是它回复 object Cannot be Cast from dbnull to other types,但是如果我连接到本地 MySql 服务器,它将成功连接
我的问题解决了。我将服务器转移到另一台服务器或从不同的位置转移,它就像一个魅力