We were testing the upgrade from 5.0.1 to 5.1.0 and came across this error. It was triggered because the primary key index is PK_EventLog not PK_EventLogMaster in our installation. The following is from the 05.01.00.log:
System.Data.SqlClient.SqlException: Table 'EventLog' already has a primary key defined on it.
Could not create constraint. See previous errors.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at DotNetNuke.Data.SqlDataProvider.ExecuteADOScript(String SQL)
at DotNetNuke.Data.SqlDataProvider.ExecuteScript(String Script, Boolean UseTransactions)
/* Change primary key of EventLog Table */
/****************************************/
IF NOT EXISTS (SELECT 1 FROM INformATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'dbo.EventLog' AND COLUMN_NAME = 'LogEventID')
BEGIN
--Note this name does NOT have an object qualifier in 4.x upgrades
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'PK_EventLogMaster'))
ALTER TABLE dbo.EventLog
DROP CONSTRAINT PK_EventLogMaster
--Note this name does have an object qualifier in 5.x installs
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'PK_EventLogMaster'))
ALTER TABLE dbo.EventLog
DROP CONSTRAINT PK_EventLogMaster
ALTER TABLE dbo.EventLog
ADD LogEventID bigint NOT NULL IDENTITY (1, 1)
ALTER TABLE dbo.EventLog
ADD CONSTRAINT PK_EventLogMaster PRIMARY KEY CLUSTERED ( LogEventID )
END
We have already edited the script and will restore the test site from our backup and retry the upgrade. However, we felt this issue needed to be shared with others.
Mike