我是新来的,我正在尝试连接到我的数据库并打开一个名为“Sintabar”的新表。我的代码有效,但数据没有进入我的表格。
Imports MySql.Data.MySqlClient
Public Class Form1
Dim conn As New MySqlConnection
Public Sub connect()
Dim DatabaseName As String = "sql6141508"
Dim server As String = "sql6.freemysqlhosting.net"
Dim userName As String = "'******'"
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("התחברת בהצלחה")
Catch ex As Exception
MsgBox(ex.Message)
End Try
conn.Close()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
connect()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
conn.Open()
Catch ex As Exception
End Try
Dim cmd As New MySqlCommand(String.Format("CREATE TABLE sintabar (id INTEGER, name TEXT, age INTEGER);"))
cmd.ExecuteNonQuery()
conn.Close()
End Sub
End Class
错误消息:
类型'System.InvalidOperationException'的未处理异常 发生在MySql.Data.dll中。 system.invalidOpertionException: {“连接必须有效且开放。”}
是的,我的用户是管理员。