system.invalidoperationException:'连接属性不得为null'在MySQL连接中
在测试项目时,我遇到了错误 “ system.invalidoperationException:'连接属性必须是非零件 。 尝试解决错误,我编辑了数据库值并重新定义Enter_email和电子邮件条目。在网上寻找问题的原因,我找到了此错误的页面,但是,没有提到我的消息或发现它的原因。我将服务器信息放入一个单独的变量中。我不确定造成此错误的原因。有人可以向我解释吗?
给出错误的代码在这里:
async void LoginClick(object sender, EventArgs args)
{
var Server = "server=myip;user=app;database=travel_logger;port=3306;password=app; default command timeout=20;";
string enter_email = Email.Text;
using (var connection = new MySqlConnection(Server))
{
connection.Open();
var cmd = new MySqlCommand("SELECT _Password FROM * WHERE email=" + enter_email);
var reader = await cmd.ExecuteReaderAsync();
string data_password = reader.GetString(0);
if (data_password == Password.Text)
{
await Navigation.PushAsync(new AboutPage());
}
else
{
await DisplayAlert("Login Error", "Incorrect email or password","Okay");
}
connection.Close();
};
}
谢谢!
While Testing the project I came across the error "System.InvalidOperationException:'Connection property must be non-null.
Attempting to fix the error, I edited database values and re-defined enter_email and the Email Entry. Looking online to find the cause of the problem, I found the page for this error, however, no reference to my message or the cause of it was found. I placed the server info into a separate variable. I'm unsure of the cause of this error. Could anyone explain it to me?
The code giving the error is here:
async void LoginClick(object sender, EventArgs args)
{
var Server = "server=myip;user=app;database=travel_logger;port=3306;password=app; default command timeout=20;";
string enter_email = Email.Text;
using (var connection = new MySqlConnection(Server))
{
connection.Open();
var cmd = new MySqlCommand("SELECT _Password FROM * WHERE email=" + enter_email);
var reader = await cmd.ExecuteReaderAsync();
string data_password = reader.GetString(0);
if (data_password == Password.Text)
{
await Navigation.PushAsync(new AboutPage());
}
else
{
await DisplayAlert("Login Error", "Incorrect email or password","Okay");
}
connection.Close();
};
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是投掷错误,因为您的命令不知道您的命令使用哪种连接。初始化时,您需要将连接传递到
mySqlCommand
。It's throw error because your command doesn't know which connection your command use. You need to pass your connection to your
MySqlCommand
when initialize.