Skip to main content

Posts

Showing posts from March, 2011

Violation of PRIMARY KEY constraint in Log Shipping

·          I have SQL Server 2005 log shipping setup with primary/secondary configuration.  I can confirm from the logs that log shipping is working without issue, however, reports generated from the monitor server show this message: Violation of PRIMARY KEY constraint 'PK__#log_shipping_mo__3ABBDC91'. Cannot insert duplicate key in object 'dbo.#log_shipping_monitor'.  The statement has been terminated. There is nothing special about the configuration.  Any ideas? ·          I think the problem you are seeing is related to some old information being present in the tables used to store log shipping configuration.  There are some scenarios where this can happen and it causes the problem you reported in your first post.  We are working on correcting this in a future release.  As you can tell from the error, the problem is caused by an insert to a temp table causing a PK constraint violation.  The PK for the temp table is server name and database name.  This error is normal

Auditing a Database in SQL Server 2005

Knowing the SPID of the current session we are using. select @@SPID To know the database name from the dbid select DB_Name (DBID) and viceversa, select db_ID (DBname) We can get the query being executed on any session using the below query. DECLARE @Handle varbinary(64); SELECT @Handle = sql_handle FROM sys.sysprocesses WHERE spid = 62; SELECT text FROM ::fn_get_sql(@Handle)