Problem
I was trying to import a BACPAC that was generated on a different server to my local development environment using SQL Server Management Studio 17.1 "Import Data-tier Application" wizard and received the following error
declare @oldName nvarchar(128) declare @newName nvarchar(128) declare @error_var int, @rowcount_var int declare @newNameCount int select @oldName = 'someUsername' select @newName = 'newUsername' begin transaction select @newNameCount = count(*) from Users where Username = @newName if @newNameCount > 0 begin RAISERROR('Username already exists. @newName=%s', 10, 1, @newName) ROLLBACK TRANSACTION RETURN end update Users set Username = @newName where Username = @oldName SELECT @error_var = @@ERROR, @rowcount_var = @@ROWCOUNT IF @rowcount_var <> 1 OR @error_var <> 0 BEGIN RAISERROR('Could not Update User.Username. @oldName=%s', 10, 1, @oldName) ROLLBACK TRANSACTION RETURN END update aspnet_Users set Username = @newName, LoweredUserName = LOWER(@newName) where LoweredUserName = LOWER(@oldName) SELECT @error_var = @@ERROR, @rowcount_var = @@ROWCOUNT IF @rowcount_var <> 1 OR @error_var <> 0 BEGIN RAISERROR('Could not Update aspnet_Users.Username. @oldName=%s', 10, 1, @oldName) ROLLBACK TRANSACTION RETURN END Commit transaction go
If you are running... | And your build number is... | Your best course of action is probably to... |
---|---|---|
SQL Server 2005 | Less than 9.0.4035 | Upgrade to Service Pack 3 (9.0.4035) or Service Pack 4 (9.0.5000), then come back for the GDR |
Exactly 9.0.4035 (SP3) | Install the SP3 GDR (9.0.4060) from KB #2494113 | |
Between 9.0.4036 and 9.0.4339 | (a) Upgrade to Service Pack 4 (9.0.5000), then come back for the GDR OR (b) Install the SP3 QFE (9.0.4340) from KB #2494112 | |
Exactly 9.0.5000 (SP4) | Install the SP4 GDR (9.0.5057) from KB #2494120 | |
Greater than 9.0.5000 | Install the SP4 QFE (9.0.5292) from KB #2494123 | |
SQL Server 2008 | Less than 10.0.2531 | Upgrade to Service Pack 1 (10.0.2531) or Service Pack 2 (10.0.4000), then come back for the GDR |
Exactly 10.0.2531 (SP1) | Install the SP1 GDR (10.0.2573) from KB #2494096 | |
Between 10.0.2532 and 10.0.2840 | (a) Upgrade to Service Pack 2 (10.0.4000), then come back for the GDR OR (b) Install the SP1 QFE (10.0.2841) from KB #2494100 | |
Exactly 10.0.4000 (SP2) | Install the SP2 GDR (10.0.4064) from KB #2494089 | |
Greater than 10.0.4000 | Install the SP2 QFE (10.0.4311) from KB #2494094 | |
SQL Server 2008 R2 | Exactly 10.50.1600 (RTM) | Install the GDR (10.50.1617) from KB #2494088 |
Between 10.50.1601 and 10.50.1789 | Install the QFE (10.50.1790) from KB #2494086 | |
Greater than 10.50.1790 (e.g. 10.50.2418 or 10.50.2425) | Wait for the final release of Service Pack 1 Watch for cumulative update or updates to MS11-049 At this time there is no fix for the CTP of SQL Server 2008 R2 SP1 |
/*Disable Constraints & Triggers*/ exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL' /*Perform delete operation on all table for cleanup*/ exec sp_MSforeachtable 'DELETE ?' /*Enable Constraints & Triggers again*/ exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL' exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL' /*Reset Identity on tables with identity column*/ exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(''?''), ''TableHasIdentity'') = 1 BEGIN DBCC CHECKIDENT (''?'',RESEED,0) END'
SELECT [TableName] = so.name, [RowCount] = MAX(si.rows) FROM sysobjects so, sysindexes si WHERE so.xtype = 'U' AND si.id = OBJECT_ID(so.name) GROUP BY so.name ORDER BY 2 DESC