今天当我在visual studio中运行我的急剧项目时,我遇到了这个错误
System.Data.Entity.dll中出现“System.Data.EntityException” 底层提供程序在Open上失败。
在它工作良好的前几天,这是我的代码,它给出了错误。 有人请帮帮我。
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.CurrentRow.HeaderCell.Value = dataGridView1.CurrentRow.Index + 1;
label2.Text = "";
dbcontext = new BookDatabase.BooksEntities();
var bookName = Convert.ToString(dataGridView1.CurrentRow.Cells[1].Value);
var book = from bok in dbcontext.Books
where bok.Title == bookName
select bok;
foreach (var bk in book)//Showing problem here, highlighting book
{
dataGridView1.CurrentRow.Cells[0].Value = bk.Code;
dataGridView1.CurrentRow.Cells[2].Value = bk.Edition;
var auto = from autho in bk.Authors
select autho;
foreach (var author in auto)
dataGridView1.CurrentRow.Cells[3].Value = author.FirstName + " " + author.LastName;
dataGridView1.CurrentRow.Cells[4].Value = bk.Price;
}
}
答案 0 :(得分:0)
它是否提供内部异常?它通常更具体。验证数据库服务器是否在线,以及连接字符串是否正确。