question

LeThienLam-3020 avatar image
0 Votes"
LeThienLam-3020 asked SeeyaXi-msft commented

Restore Database SQL Server 2016 from .bacpac file!

Hi Everyone!
I get error when Restore Database SQL Server from .bacpac file:
"Violation of PRIMARY KEY constraint 'PK_SQL_Chan_5E5499A845A1F8E0'. Cannot insert duplicate key in object 'dbo.SQL_ChangeLog'. The duplicate key value is (1).
The statement has been terminated. (.Net SqlClient Data Provider)"
Please help me fix this error. Thanks!

sql-server-general
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @LeThienLam-3020,

We have not received a response from you. Did the reply could help you? If the response helped, do "Accept Answer". If it is not help, please let us know the progress. Your contribution is highly appreciated.

0 Votes 0 ·

1 Answer

SeeyaXi-msft avatar image
0 Votes"
SeeyaXi-msft answered SeeyaXi-msft commented

Hi @LeThienLam-3020

This error message indicates that there are duplicate records in your data.
Creating a bacpac on SQL Server does not guarantee transactional consistency when doing an export of a live, changing database.
There are two situations:
1. Duplication between the existing table and the data to be imported
At this time, you can find duplicate records by establishing an association between the two tables with cascading the primary key
2. There are duplicate records in the table to be imported
The duplicate records in the table can be found out by a statement similar to the following
select StudentCode from StudentScore group by StudentCode[here is the PRIMARY KEY field] having count(*)>1
Finally, delete the duplicate records by sorting out.


If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank @SeeyaXi-msft . I think file .bacpac error. I will process backup database again.

0 Votes 0 ·

Hi LeThienLam-3020,

What's more, to restore .bacpac file you will need the latest SQL Server Management Studio (SSMS), a local instance of SQL Server, either Express or any full version, and your .bacpac file.

Best regards,
Seeya

0 Votes 0 ·