在一台机器上出现 DacServices 错误,而不是在另一台机器上

Getting DacServices error on one machine, not on another

我们有一个过程,包括在 SQL 服务器 11 和 10 数据库服务器上创建数据库。我们正在使用 dacpac 通过 DacServices 在 C# 中导入此数据。这是正在使用的代码:

var dac = new DacServices(masterConnString);
using (var bacPac = BacPackage.Load(templatePath))
{
    dac.ImportBacpac(bacPac, dealer.VSID.ToString(CultureInfo.InvariantCulture));
}

当我们 运行 从我们的本地机器进行初始测试时,它按预期工作。然而,当我把它扔到服务器上时(它 运行s 作为 WCF 服务的一部分)。我收到以下错误:

The type initializer for 'Microsoft.SqlServer.Dac.DacServices' threw an exception.

Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at IWcfService.Method(String string, Int32 integer) at WcfServiceClient.Method(String string, Int32 integer)

提前致谢。

我终于弄明白了。有问题的 DLL 是 Microsoft.SqlServer.TransactSql.ScriptDom。一旦我引用了它,一切都按预期进行。花了很多挖掘才能到达那个地方。