SQL Server 对等复制配置失败后无法删除重建,报错:Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be im

数据库迁移惯用SSMS来进行视图操作,但是在视图迁移完成后进行对等复制的配置,到最后一步时报错,订阅的部分没有成功创建。

如下图:

SQL Server 对等复制配置失败后无法删除重建,报错:Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be im

没有办法只能删除对等复制并重建,但是在删除时报错如下:Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be impersonated, or you do not have permission.

在网上查了下资料并咨询了下同事后来找到原来是微软的bug:http://social.msdn.microsoft.com/forums/en-US/sqltools/thread/91a27e23-c760-4ac1-80f4-0fac220c1adb/

This is a known issue when attaching a database through SSMS using a login which is not sysadmin, one hits this error.

The workaround for this currently is to use T-SQL to attach database .

CREATE DATABASE [databasename] ON

( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\databasename.mdf' ),

( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\databasename_log.LDF' )

FOR ATTACH

执行下面的脚本后可以删除:

USE [xxxx]
GO
EXEC dbo.sp_changedbowner @loginame = N'sa', @map = false
GO

对于复制的删除可以通过视图操作,也可以使用下面的脚本:

ECLARE @publication AS sysname
DECLARE @publicationDB AS sysname
SET @publication = N'TOPUSA'
SET @publicationDB = N'TOPUSA'

-- Remove the publication.
USE [TOPUSA]
EXEC sp_droppublication @publication = @publication;

-- Remove replication objects from the database.
USE master
EXEC sp_droppublication
@dbname = @publicationDB,
@optname = N'publish',
@value = N'false'
GO

 

对等复制删除的详细操作步骤可以参照以下链接:http://msdn.microsoft.com/en-us/ms151256(SQL.90).aspx 。

你可能感兴趣的:(sql,server)