将 Windows 8 应用程序连接到 MySQL [英] Connect Windows 8 app to MySQL
本文介绍了将 Windows 8 应用程序连接到 MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 C# 制作我的第一个 Windows 8 应用程序.我有一个想要连接的 MySQL 数据库.我以前用 Windows 窗体做过这个,一切都很顺利.但是,使用 Windows 8 应用程序时,它无法连接.
I am making my first Windows 8 app using C#. I have a MySQL Database that I would like to connect to. I have done this before with windows forms and everything went smoothly. However with the windows 8 app it won't connect.
这是我的连接字符串:
string myConnectionString = "Server=mysql9.000webhost.com; Database=a2236339_snooker; Uid=a2236339_joe; password=TeamPr0ject;";
代码如下:
MySqlConnection connection = new MySqlConnection(myConnectionString);
connection.Open();
然后像这样打开我的连接.
and then open my connection like that.
我得到的错误是
MySql.Data.RT.DLL 中发生了MySql.Data.MySqlClient.MySqlException"类型的异常,但未在用户代码中处理
An exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.RT.DLL but was not handled in user code
谁能解释为什么会这样以及我做错了什么?
Can anyone explain why this is and what I am doing wrong?
推荐答案
using (MySqlConnection connection = new MySqlConnection("server=YOUR_SERVER;database=YOUR_DATABASE;uid=YOUR_USERNAME;password=YOUR_PASSWORD;"))
{
connection.Open();
MySqlCommand userinfoCommand = new MySqlCommand("SELECT name, FROM table",connection);
using (MySqlDataReader reader = userinfoCommand.ExecuteReader())
{
while (reader.Read())
{
String name= reader.GetString("name");
}
connection.Close();
}
}
这篇关于将 Windows 8 应用程序连接到 MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文