我正在尝试保存员工详细信息,其中包含对City的引用.但每当我尝试保存我的联系人时,我都会得到例外"ADO.Net实体框架实例对象不能被IEntityChangeTracker的多个实例引用"
我读了这么多帖子,但仍然没有弄清楚该怎么做...我的保存按钮点击代码如下
protected void Button1_Click(object sender, EventArgs e)
{
EmployeeService es = new EmployeeService();
CityService cs = new CityService();
DateTime dt = new DateTime(2008, 12, 12);
Payroll.Entities.Employee e1 = new Payroll.Entities.Employee();
Payroll.Entities.City city1 = cs.SelectCity(Convert.ToInt64(cmbCity.SelectedItem.Value));
e1.Name = "Archana";
e1.Title = "aaaa";
e1.BirthDate = dt;
e1.Gender = "F";
e1.HireDate = dt;
e1.MaritalStatus = "M";
e1.City = city1;
es.AddEmpoyee(e1,city1);
}
Run Code Online (Sandbox Code Playgroud)
和Employeeservice代码
public string AddEmpoyee(Payroll.Entities.Employee e1, Payroll.Entities.City c1)
{
Payroll_DAO1 payrollDAO = new Payroll_DAO1();
payrollDAO.AddToEmployee(e1); //Here I am getting Error..
payrollDAO.SaveChanges(); …Run Code Online (Sandbox Code Playgroud) 我们有一个在服务器上运行的网站.我们有一个"生产"实例和一个"临时"实例,每个实例都有自己的数据库.MSSQL Server在同一服务器上本地运行.
今天,突然"生产"网站倒闭了.查看日志,出现以下异常:
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
Run Code Online (Sandbox Code Playgroud)
与此同时,"升级"网站正常运作.
在尝试弄清楚发生了什么的同时,我尝试了各种各样的事情,比如重新创建应用程序池和IIS应用程序.我还将"生产"IIS应用程序连接到"临时"应用程序的同一个应用程序池,仍然是同样的问题.当然也重启了服务器.
此外,我直接运行"生产"网站的可执行文件(作为控制台应用程序),它正常工作.所以这只是在IIS下运行时才会出现的问题.
我尝试的最后一件事是,我重新配置了"登台"网站以使用"生产"数据库,并且我完全震惊它正常工作.因为我认为问题是"生产"数据库本身.
我根本不知道这里发生了什么.很感谢任何形式的帮助.