如何使用VB.net连接Web服务器数据库是MySQL [英] How to use VB.net connect Web-server database is MySQL
问题描述
导入System.Data
导入MySql.Data.MySqlClient
导入System.Data.SqlClient
公共类Form1
Dim serverstring As String =server = ....; user id = .....; password = .....; database = .....;
Dim sqlconnection As MySqlConnection = New MySqlConnection
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles MyBase.Load
sqlconnection.ConnectionString = serverstring
尝试
如果sqlconnection.State = ConnectionState.Closed那么
sqlconnection.Open()
MsgBox( เชื่อมต่อสำเร็จ)
否则
sqlconnection.Close()
结束如果
Catch ex As Exception
MessageBox.Show(错误:&ex.Message&)
结束
结束尝试
结束子
此代码此ca n只使用Localhost,但是如果我想在线连接到另一台主机怎么办?谁知道..请帮我
真的是你唯一需要的东西要更改是[server / DomainName]的'server ='部分,并可能指定一个端口。另一个问题是允许通过防火墙连接MySQL服务器。端口3306是MySQL的默认端口。
MySQL连接字符串
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
Public Class Form1
Dim serverstring As String = "server=....;user id=.....;password=.....;database=.....;"
Dim sqlconnection As MySqlConnection = New MySqlConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sqlconnection.ConnectionString = serverstring
Try
If sqlconnection.State = ConnectionState.Closed Then
sqlconnection.Open()
MsgBox("เชื่อมต่อสำเร็จ")
Else
sqlconnection.Close()
End If
Catch ex As Exception
MessageBox.Show("Error : " & ex.Message & "")
End
End Try
End Sub
this code this can use only Localhost, but how can I do if I want to connect to another Host online, Who know ..help me please
Really the only thing you need to change is the 'server=' part to the [IP/DomainName] and possibly specify a port. The other issue would be allowing a connection to the MySQL server through the firewall. Port 3306 is the default port for MySQL.
MySQL Connection Strings
这篇关于如何使用VB.net连接Web服务器数据库是MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!