【发布时间】:2017-01-17 13:52:05
【问题描述】:
我最近刚刚开始将我的 Raspberry Pi 用于一个新项目。 我已经设置了 MySql 数据库(与 IPadress/phpmyadmin 的连接有效) 现在我想将数据库包含在我的 C# 项目中,但是当我运行它时,我从我的 try/catch 中收到无法连接的消息。问题可能出在哪里? 我知道这可能听起来很傻,但实际上我被困住了。
using MySql.Data.MySqlClient;
namespace MyRecipe
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string connetionString = null;
MySqlConnection cnn;
connetionString = "server='IP-RaspberryPI';database=recipe;uid=recipe;pwd=secret;";
cnn = new MySqlConnection(connetionString);
try
{
cnn.Open();
MessageBox.Show("Connection Open ! ");
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! ");
}
}
}
}
【问题讨论】:
-
看看我的回答,我相当肯定你的用户没有正确的权限所以你需要通过 SSH 连接到你的 pi
-
Als 将您的 MessageBox 错误更改为 MessageBox.Show("Error Message: " + ex.Message);所以你可以告诉我们真正的错误
标签: c# mysql database-connection