为什么这个错误连接数据库asp.net mvc
Why is this error connection database asp.net mvc
为什么会出现这个错误
An exception of type 'System.Data.Entity.Core.EntityException'
occurred in EntityFramework.SqlServer.dll but was not handled in user
code
使用时:
department data = conn.dep_con.Single(x => x.depId == id);
web.config
<connectionStrings>
<add name="DataBaseConn" connectionString="Data Source=localhost;Initial Catalog=companye;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
这是因为您的 table 中没有当前 depId 的数据,请尝试将您的代码更改为此,看看它是否能解决您的问题。
department data = conn.dep_con.SingleOrDefault(x => x.depId == id);
为什么会出现这个错误
An exception of type 'System.Data.Entity.Core.EntityException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
使用时:
department data = conn.dep_con.Single(x => x.depId == id);
web.config
<connectionStrings>
<add name="DataBaseConn" connectionString="Data Source=localhost;Initial Catalog=companye;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
这是因为您的 table 中没有当前 depId 的数据,请尝试将您的代码更改为此,看看它是否能解决您的问题。
department data = conn.dep_con.SingleOrDefault(x => x.depId == id);