如何使用VB.NET连接到MySql? [英] How to connect to MySql using VB.NET?

查看:260
本文介绍了如何使用VB.NET连接到MySql?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直有这个问题超过一个星期了,我想解决它。每次我尝试连接到我的MySQL数据库时,我都会收到此错误:



I've been having this problem for over a week now and I want to fix it. Everytime I try to connect to my MySQL Database I keep on getting this error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)





*我已下载并导入最新的用于VB.NET的MySQL连接器

*我启用了所有IP / TCP连接

*我启用了所有远程连接

*我已禁用防火墙和防火墙-Virus Systems

*我正在使用最新的连接字符串



有人可以帮帮我吗?这是我的代码:





* I downloaded and Imported the latest MySQL Connector for VB.NET
* I Enabled all IP/TCP Connections
* I Enabled all Remote Connections
* I Disabled Firewall and Anti-Virus Systems
* I'm using the latest Connection String

Could someone please help me? Here's my code:

Imports System.Data.SqlClient
Public Class LoginForm1
    Dim conn As SqlConnection
    ' TODO: Insert code to perform custom authentication using the provided username and password 
    ' (See http://go.microsoft.com/fwlink/?LinkId=35339).  
    ' The custom principal can then be attached to the current thread's principal as follows: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication. 
    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
    ' such as the username, display name, etc.

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        conn = New SqlConnection
        conn.ConnectionString = "Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"
        Try
            conn.Open()
            MsgBox("Connected!")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
     End Sub





我也在使用Host Gator作为MySQL数据库。我想知道我是否在主机gator中使用正确的服务器名称。我使用了主机gator cPanel左下角的IP地址。我还在白名单远程连接中放了一个%。



Also I'm using Host Gator for the MySQL Database. I wanna know if I'm using the right server name in host gator. I used the IP Address in the bottom left corner of cPanel of host gator. I also put a % in the whitelist remote connection.

推荐答案

我猜你已经看过这些/他们的技术帮助了吗?



http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely [ ^ ]



http://support.hostgator.com / articles / cpanel / how-to-connect-to-mysql-database-remote [ ^ ]



首先,我' d在本地计算机上放置类似MySQL Workbench的东西来帮助管理数据库并检查连接 - 一旦从那里获得正确的连接,就可以将它添加到程序的连接字符串中,这让我想到这个...



你没有显示你使用的连接字符串 - 但它看起来像是在试图找到一个本地数据库(命名管道)而不是通过网络使用tcp / udp ..所以,请指出你的连接字符串(更新你的答案)



顺便说一句,我在他们的网站上找不到任何东西关于如何将托管数据库的连接字符串放在一起,所以我希望你有更多信息



'g'
I'm guessing you've seen these/been all over their tech help ?

http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely[^]

http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely[^]

To start with, I'd put something like the MySQL Workbench on your local machine to help management of your database and check connectivity - once you get the connectivity correct from there, you can then add it to the connection string of a program, which brings me to this ...

you don't show the connection string you used - but it looks like its trying to find a local DB (named pipes) rather than across the network with tcp/udp .. so, please indicate your connection string (update your answer)

btw, I couldn't find anything on their site about how a connection string to their hosted db's is put together, so I hope you have more information

'g'


解决方案解决了!



我终于把它连接起来感谢家伙ROOKIE MISTAKE LOL



我忘了添加MySQL的参考资料。我添加了DLL但我忘了添加引用!



我还将导入更改为Imports MySql.Data.MySQLClient并将每个Sql编码更改为MySQL !我猜它是使用Microsoft SQL Server而不是MYSQL!
Solution Solved!

I finally got it connected thanks guys ROOKIE MISTAKE LOL

I forgot to add the references of MySQL. I added the DLL's but I forgot to add the references!

I also changed the imports to "Imports MySql.Data.MySQLClient" and changed the every Sql coding to MySQL! I guess it was using Microsoft SQL Server instead of MYSQL!


这篇关于如何使用VB.NET连接到MySql?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆