Asp.net 已添加具有相同密钥的项。切换web主机后

Asp.net 已添加具有相同密钥的项。切换web主机后,asp.net,sql-server,entity-framework,Asp.net,Sql Server,Entity Framework,我正在将.NET Framework 4.0站点从一个web主机转移到另一个web主机。现有主机上的站点似乎正在按预期运行。但是,在将站点文件和数据库传输到新主机,然后修复web.config连接字符串以指向新数据库之后,我在尝试访问从数据库提取的页面时出错 我没有写这个网站,但它似乎是使用代码优先设置 Server Error in '/' Application. An item with the same key has already been added. Description: A

我正在将.NET Framework 4.0站点从一个web主机转移到另一个web主机。现有主机上的站点似乎正在按预期运行。但是,在将站点文件和数据库传输到新主机,然后修复web.config连接字符串以指向新数据库之后,我在尝试访问从数据库提取的页面时出错

我没有写这个网站,但它似乎是使用代码优先设置

Server Error in '/' Application.
An item with the same key has already been added.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An item with the same key has already been added.

Source Error:


Line 130:                if ((_Jobs == null))
Line 131:                {
Line 132:                    _Jobs = base.CreateObjectSet<Job>("Jobs");
Line 133:                }
Line 134:                return _Jobs;
连接字符串:

<connectionStrings>
<add name="PREntities" connectionString="metadata=res://*/App_Code.PRModel.csdl|res://*/App_Code.PRModel.ssdl|res://*/App_Code.PRModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=myserver.com;Initial Catalog=mydatabase;Persist Security Info=True;User ID=username;Password=password;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
<add name="ConnectionStringDB" connectionString="Data Source=myserver.com;Initial Catalog=mydatabase;Persist Security Info=True;User ID=username;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>


您是如何传输数据库的?能否显示调用堆栈?我敢打赌,实际问题是您有两个同名的连接字符串。web主机向我发送了一个database.bak文件,我将它导入到我电脑上的本地sqlexpress中,然后导出到新的webhost数据库中。这很可能是一个错误-您正在尝试添加一个已存在的实体-查看该侧您可能做错了什么。很难帮上忙,你是怎么导出的?SQL Management Studio中的“导出数据”函数不会重新创建增加主键的标识规范。代码可能正在尝试插入Id为0的行。
<connectionStrings>
<add name="PREntities" connectionString="metadata=res://*/App_Code.PRModel.csdl|res://*/App_Code.PRModel.ssdl|res://*/App_Code.PRModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=myserver.com;Initial Catalog=mydatabase;Persist Security Info=True;User ID=username;Password=password;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
<add name="ConnectionStringDB" connectionString="Data Source=myserver.com;Initial Catalog=mydatabase;Persist Security Info=True;User ID=username;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>