cuốn sách gpt4 ai đã làm

c# - 系统。无效操作异常

In lại Tác giả: Walker 123 更新时间:2023-11-28 23:17:22 31 4
mua khóa gpt4 Nike

我正在尝试制作一个带有登录系统的程序我对此很陌生,但我已经连续工作 8 个小时试图解决这个问题。这是我得到的错误代码

+ ServerVersion 'con.ServerVersion' threw an exception of type 'System.InvalidOperationException' string {System.InvalidOperationException}

这是我的代码

    private void LogB_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=Myip;user id=MyId;database=MyDb;password=MyPw;persistsecurityinfo=True");
SqlDataAdapter sda = new SqlDataAdapter("Select * From login where navn='"+ TULog.Text + "' and pw='" + TPLog.Text + "'",con);

thử
{

con.Open();


}
catch (SqlException ex)
{
MessageBox.Show(ex.ToString());
throw ex;
}
Cuối cùng
{
con.Close();
}
}
}
}

抱歉,如果这看起来有些废话,但我是一个正在努力学习的人 :p

câu trả lời hay nhất

此异常告诉您在 SqlConnection 关闭时尝试访问 con.ServerVersion tài sản.

từ SqlConnection.ServerVersion 上的 MSDN属性:

InvalidOperationException - The connection is closed. ServerVersion was called while the returned Task was not completed and the connection was not opened after a call to OpenAsync.

您在上面显示的代码没有显示对此属性的调用,您必须在其他地方这样做。无论如何,在这样做之前需要打开连接。

关于c# - 系统。无效操作异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43298264/

31 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress