我正在做一些自动化操作,并且正在将一些 10-15 个旧的、古怪的脚本重写为一个简单的单元,它可以:
- 生产环境从MsSql2012导出数据库方案
- 开发环境导入数据库方案到MsSql2012
我使用Microsoft.SqlServer.Dac执行此操作,我可以在其中导出/导入 dac 包。
它工作得很好:),但是在完成了我所有的 TDD 和测试之后,是时候做真正的事情了,结果我完全错过了我们在工作中拥有 2 个域的情况。
这意味着当我在开发环境中导入 dacpac 时出现错误,因为我们的 2 个域没有完全的 2 路信任,当然数据库有来自这两个域的用户。特别是生产域用户。我可以看到 3 个可行的解决方案:
- 在环境之间获得完全信任。但这不会发生,因为我的工作实施了高水平的安全性。
- 导入没有用户的 dacpac。
- 在没有用户的情况下导出到 dacpac。
我已经阅读了文档(当然这是模糊的),试图找到一组可以实现 2)或 3)的选项。我测试了很多组合,但没有一个会起作用。dac pac 导入不断尝试创建用户并失败,因为无法在开发环境中验证生产用户。
我使用 Deploy 和 Extract 来导出/导入。可以在此处找到不同的选项:
- 提取:http ://technet.microsoft.com/en-us/library/microsoft.sqlserver.dac.dacextractoptions.aspx
- 部署:http ://technet.microsoft.com/en-us/library/microsoft.sqlserver.dac.dacdeployoptions.aspx
我没有找到有效的组合,我什至阅读了表明它是 DacPac 中的错误的帖子。但我不确定。我现在正在研究的最后一个选项是使用 GenerateScript 方法,该方法有望强制排除用户/登录名,但我担心它也不起作用。请参阅 ( http://technet.microsoft.com/en-us/library/hh753526.aspx )。
问题: 如何在导出或导入中从我的 dacpac 中排除用户/登录?
更新
当前提取设置:
IgnoreUserLoginMappings = true,
VerifyExtraction = false,
当前部署设置:
CreateNewDatabase = true,
DeployDatabaseInSingleUserMode = true,
DisableAndReenableDdlTriggers = true,
IgnoreUserSettingsObjects = true,
更新
到目前为止,一切都指向一个丑陋的解决方案。
I can generate a deploy script using DacServices.
Then i can parse the script (Remove logins etc).
Then write the result to a file.
And then call SQLCMD in an external process given it the generated and parsed file.
Finally i must evaluate the result from the SQLCMD process.
使用 SQLCMD 的原因是生成的脚本显然不是纯 tsql,而是使用 ':setvar' 的东西,据我所知,只有 SQLCMD 可以处理。来吧MS...
同样,如果有人知道在 C# 中执行此操作的更好方法,或者知道 DacPac 程序集的错误修复/更新,请分享。:)
更新
我发现 IgnorePartitionSchemes 之类的东西也不起作用。似乎命名空间 Microsoft.SqlServer.Dac 不仅有一点问题,而且非常有问题或缺乏实现。