I have copied a development database to another instance on the same server for QA testing. The database name was changed from XXX_Dev to XXX_Test. The platform is SQL Server 2005. Inserting a new record produces this error:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Patient_AddressId". The conflict occurred in database "XXX_Test", table "dbo.XXX_Address", column "AddressId"
I first took this problem to the SQL Server forums on MSDN. I have traced the SQL in Profiler and it executes fine when I paste it into SSMS. I now believe the problem is in the Data Connection configuration of my DBML file, but I have been unable to adjust
the settings so that it is happy. I found some threads around that talk about programmatically setting the connection, but this application does not need that - I just want to set it once. I would be happy to hear any suggestions as to what I am missing.
The problem has been identified, and was not in the DBML. There was a hard-coded reference to the database name in one of the stored procedures. See the detailed discussion at:
echotrain
Member
22 Points
15 Posts
Foreign Key Conflict in Test Database and DBML
Apr 09, 2012 08:30 PM|LINK
I have copied a development database to another instance on the same server for QA testing. The database name was changed from XXX_Dev to XXX_Test. The platform is SQL Server 2005. Inserting a new record produces this error:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Patient_AddressId". The conflict occurred in database "XXX_Test", table "dbo.XXX_Address", column "AddressId"
I first took this problem to the SQL Server forums on MSDN. I have traced the SQL in Profiler and it executes fine when I paste it into SSMS. I now believe the problem is in the Data Connection configuration of my DBML file, but I have been unable to adjust the settings so that it is happy. I found some threads around that talk about programmatically setting the connection, but this application does not need that - I just want to set it once. I would be happy to hear any suggestions as to what I am missing.
SonicMan
Participant
1472 Points
228 Posts
Re: Foreign Key Conflict in Test Database and DBML
Apr 11, 2012 03:16 AM|LINK
Hi
Please check
How to set the connection string in your LINQ dbml file dynamically (based on web.config)
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: Foreign Key Conflict in Test Database and DBML
Apr 11, 2012 03:29 AM|LINK
Hi
Linq use the connection string in web.config.
You can try to change the connectionstring in your Web.config file to your test DB. And Rebuild the programe.
And I suggest you don't modify the DB name.
You can create a TestFolder and a Original Folder and copy the DB to this 2 folder, That's more safety.
hope it helpful.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
echotrain
Member
22 Points
15 Posts
Re: Foreign Key Conflict in Test Database and DBML
Apr 11, 2012 01:57 PM|LINK
The problem has been identified, and was not in the DBML. There was a hard-coded reference to the database name in one of the stored procedures. See the detailed discussion at:
http://social.msdn.microsoft.com/Forums/en-US/sqltools/thread/37603fae-ade2-49c0-9421-227a3c2a0d71
Thanks to SonicMan and Dino He for the suggestions on working with the connecton string.