是的,我知道这是一个记录严重的问题。我也知道那里有很多“答案”。但是,这些答案中没有一个能解决我遇到的问题。我尝试了许多不同的网站和许多不同的主题,所以当我说我尝试过所有内容时你可以信任我。这是我的新帐户表单的代码,它是我程序的一部分。我的主要问题是,当我尝试连接时,程序无法访问数据库。它声明“它无法连接到任何指定的MySQL主机”。这是我的代码:
Imports MySql.Data.MySqlClient
Public Class NewAccount
Dim conn As New MySqlConnection
Public Sub connect()
Dim DatabaseName As String = "db709866308"
Dim server As String = "db709866308.db.1and1.com"
Dim userName As String = "db709866308"
Dim password As String = "*******"
If Not conn Is Nothing Then conn.Close()
conn.ConnectionString = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, userName, password, DatabaseName)
Try
conn.Open()
MsgBox("Connected")
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim con As New MySqlConnection
Dim Password As String
Dim Password2 As String
Dim userName As String
'''''''''''''''''''''''''''''''''''''''''''''''Encryption goes under this line''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim plainText As String
Dim cipherText As String
Dim passPhrase As String
Dim saltValue As String
Dim hashAlgorithm As String
Dim passwordIterations As Integer
Dim initVector As String
Dim keySize As Integer
plainText = Pword.Text ' original plaintext
passPhrase = "Pas5pr@se" ' can be any string
saltValue = "s@1tValue" ' can be any string
hashAlgorithm = "SHA1" ' can be "MD5"
passwordIterations = 2 ' can be any number
initVector = "@1B2c3D4e5F6g7H8" ' must be 16 bytes
keySize = 256 ' can be 192 or 128
cipherText = RijndaelSimple.Encrypt _
(
plainText,
passPhrase,
saltValue,
hashAlgorithm,
passwordIterations,
initVector,
keySize
)
plainText = RijndaelSimple.Decrypt _
(
cipherText,
passPhrase,
saltValue,
hashAlgorithm,
passwordIterations,
initVector,
keySize
)
'''''''''''''''''''''''''''''''''''''''''''''''Encryption goes above this line''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Try
conn.Open()
Catch ex As Exception
MessageBox.Show("Error while connecting to Server. " & ex.Message)
End Try
Dim cmd As New MySqlCommand(String.Format("INSERT INTO `auth` VALUES User.text, ciphertext"))
Try
cmd.ExecuteNonQuery()
conn.Close()
Catch ex As Exception
MsgBox("Couldn't Access Database")
End Try
End Sub
我还想强调,这不是完整的代码,只是包含某种形式连接的部分。
非常感谢提前。