如何将vb.net 10表单连接到在线数据库 [英] How do i connect vb.net 10 form to the online database

查看:91
本文介绍了如何将vb.net 10表单连接到在线数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我希望我的Windows窗体连接到在线数据库,

我的意思是我有一个mysql数据库phpmyadmin,在我的托管服务提供商上。

我正在创建一个必须从这个数据库获取数据的Windows表单。



i下载并安装了连接器,并使用代码连接到数据库,但我收到一条错误,上面写着无法连接到任何指定的MySQL主机。



什么我试过了:



Imports System.Data.SqlClient

Imports MySql.Data.MySqlClient



Public Class Form1

Dim con As New MySqlConnection

Dim cmd As New MySqlCommand





Private Sub Form1_Load(sender As System.Object,e As System.EventArgs)处理MyBase.Load

con.ConnectionString =server = localhost;端口= 3306; user id = myuserid;密码=输入mypassword; database = mydatabasename

con.Open()'错误在这一行

cmd.Connection = con



Dim adp As New MySqlDataAdapter

Dim ds As New DataSet

cmd.CommandText =从table_name中选择fname,其中name ='xyz'

Me.TextBox1.Text = ToString(cmd.ExecuteScalar)

End Sub

结束班级





我很抱歉,如果我不清楚,但我需要帮助

Hello,

I wanted my windows form to be connected to the online database,
I mean I have a mysql database on phpmyadmin, on my hosting provider.
I am creating a windows form that must get data from this database.

i downloaded and installed the connector, and used a code to connect to the data base but i get a error that says "Unable to connect to any of the specified MySQL hosts.

What I have tried:

Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient

Public Class Form1
Dim con As New MySqlConnection
Dim cmd As New MySqlCommand


Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "server=localhost;port=3306; user id=myuserid; password=mypassword; database=mydatabasename"
con.Open() 'Error is in this line
cmd.Connection = con

Dim adp As New MySqlDataAdapter
Dim ds As New DataSet
cmd.CommandText = "Select fname from table_name where name='xyz'"
Me.TextBox1.Text = ToString(cmd.ExecuteScalar)
End Sub
End Class


I am sorry if I am not clear in any basis, but i need help

推荐答案

localhost仅适用于同一台机器上的数据库 - 大多数托管服务将数据库和Web服务器分开(或者更常见的是有一个数据库服务器场),因此您需要与他们讨论连接字符串应该是什么。只有他们可以告诉您,因为它需要SQL服务器名称,以及您的数据库用户名和密码 - 这些将是每个托管服务不同。

只是为了生活更有趣的是,您需要检查托管服务是否允许远程连接 - 有些人这样做,但许多不是出于安全原因。如果他们不这样做,那么您只能从网站服务器代码访问数据库 - 而不是从远程PC应用程序访问。
localhost is for databases on the same machine only - most hosting services separate the database and web servers (or more usually have a database server farm) so you need to talk to them about exactly what the connection string should be. Only they can tell you, as it will need the SQL server name, together with your DB username and password - and these will be different for every hosting service.
Just to make life even more fun, you will need to check if the hosting service allows "remote connections" - some do, but many don't for security reasons. If they don't, then you can only access the DB from the website server code - not from a remote PC application.


这篇关于如何将vb.net 10表单连接到在线数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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