目标
使用 PowerShell 脚本将 SQL 数据库克隆到不同的远程 SQL Server
什么有效
使用 SSMS 将 BACPAC 文件导入不同的服务器(远程和本地)不会出现(报告)警告或错误。
什么没有
使用 sqlpackage.exe 和 PowerShell dbatools 将 BACPAC 导入远程 SQL Server 会导致以下错误:
Warning SQL72038: The object [XXX] already exists in database with a different definition and will not be altered.
Error SQL72014: .Net SqlClient Data Provider: Msg 15023, Level 16, State 1, Line 1 User, group, or role 'XXX' already exists in the current database.
Error SQL72045: Script execution error. The executed script:
CREATE USER [XXX] FOR LOGIN [XXX];
我还尝试使用 PS dbatools DACPAC 方法:https ://dbatools.io/clone/
具有不同设置的错误消息更改为:
Initializing deployment (Start)
The object [XXX] already exists in database with a different definition and will not be altered.
Initializing deployment (Complete)
Analyzing deployment plan (Start)
Analyzing deployment plan (Complete)
Reporting and scripting deployment plan (Start)
Reporting and scripting deployment plan (Complete)
Updating database (Start)
Creating NEW_DATABASE...
The database settings cannot be modified. You must be a SysAdmin to apply these settings.
Creating [XXX]...
.Net SqlClient Data Provider: Msg 15023, Level 16, State 1, Line 1 User, group, or role 'XXX' already
exists in the current database.
Script execution error. The executed script:
CREATE USER [XXX] WITHOUT LOGIN;
An error occurred while the batch was being executed.
Updating database (Failed)
下一步是禁用用户并通过脚本添加回所需的用户和角色。使用以下链接作为参考,我无法使用我们现有的管理员登录名和密码删除数据库。
为了解决这个问题,我们必须在 RDS 中更改我们的管理员密码
笔记
- 我无法删除用户 XXX,因为它已映射到不同的数据库
- SQL Server Management Studio v17.9.1
- PowerShell dbatools v1.0.30
问题
- 有没有办法找出 SSMS 正在执行什么,以便我可以通过脚本复制它?
- 有哪些选项可以解决此问题?