【问题标题】:SqlPackage.exe - "System.StackOverflowException"SqlPackage.exe -“System.StackOverflowException”
【发布时间】:2018-05-26 18:05:53
【问题描述】:

我有一系列由 TFS 代理运行的 PowerShell 脚本,它们是构建过程的一部分。这些在publish a series of DACPAC's 到一组给定数据库的几台服务器(Windows Server 2012 R2)上运行。最近我把所有的 TFS 构建代理都更新到了最新版本(TFS 2018)

今天我注意到我的构建过程中的这些服务器之一不再运行,特别是由于“System.StackOverflowException”错误而无法运行“SqlPackage.exe”(非常适合此站点)。

可以通过手动运行 power shell 脚本来重现同样的问题,但仅在这台服务器上,所有其他服务器都可以正常运行。脚本如下所示:

$arguments = '/a:Publish /pr:"' + $scriptPath + $database + ".publish.xml" + '" /sf:"' + $dacPac + '" /tcs:"Data Source=' + $servername + ';Persist Security Info=True;User ID=' + $username + ';Password=' + $password + ';Pooling=False;MultipleActiveResultSets=False;Connect Timeout=60;Encrypt=False;TrustServerCertificate=True"'

Start-Process -FilePath "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130\SqlPackage.exe" -ArgumentList $arguments -NoNewWindow -PassThru -Wait

手动运行时,调试的异常是:

Microsoft.SqlServer.TransactSql.ScriptDom.dll 中出现“System.StackOverflowException”类型的未处理异常

我真的不确定这台服务器上的什么配置会导致这种问题。资源方面,服务器非常强大,有大量可用内存,其他服务器运行得很好。我尝试了各种版本的“SqlPackage”(13, 14),但似乎没有任何效果。我已经换掉了 DacPac,但这似乎也不起作用......

以前有人见过这个问题吗?什么样的服务器配置会导致此类问题?

更新 1:嗯,只需切换到新的“14.0”、“SqlPackage.exe”,现在我的所有机器上都安装了它,我想知道它是否与任何相关dll,比如我在SSDT中安装的那些。

其实现在想想,我觉得这个问题是在我第一次安装VS 2017的时候出现在服务器上的,不知道对“SqlPackage.exe”有影响吗?

我也找到了这个interesting post,我想知道我是否可以通过这种方式解决它...

【问题讨论】:

  • 由于您可以在服务器机器上手动重现此问题,因此您的问题与 TFS 无关。您使用的是哪个版本的 SQL Server?您可以尝试在 SQL Server 功能包中重新安装 x64 和 x86 版本的 SqlDom.msi。
  • @CeceDong,是的,没有运气,我尝试了多个版本的 SqlPackage,如问题中所述,但导致崩溃的原因会影响两个版本,我认为这是环境问题,我可能只是重新格式化服务器,但最好把它确定下来,这样其他人就不必像我一样遇到这个问题。

标签: sql-server sqlpackage


【解决方案1】:

我从来没有想出如何为“SqlPackage”解决这个问题,我们最终创建了自己的包部署器控制台应用程序并通过控制台应用程序(“DacpacDeployUtility”)调用它:

static int Main(string[] args)
{
    try
    {
        string destinationServer = args[0];
        string destinationDatabase = args[1];
        string userID = args[2];
        string password = args[3];
        string publishFileFullPath = args[4];
        string dacpacFileFullPath = args[5];

        SetupRegistryQueryExecutionTimeout();
        PublishDacpacSimple(destinationServer, destinationDatabase, userID, password, publishFileFullPath, dacpacFileFullPath);

        return 0; //where 0 = success
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error in Main: " + ex.Message + "\n" + ex.StackTrace);

        for (int i = 0; i < args.Length; i++)
        {
            Console.WriteLine("Value in args[" + i + "]: " + (i == 3 ? "**********" : args[i]));
        }

        Console.WriteLine("Failed to publish dacpac.");

        //Return error state
        return 1;
    }
}

private static void SetupRegistryQueryExecutionTimeout()
{
    //Fixes an annoying issue with slow sql servers: https://stackoverflow.com/a/26108419/2912011
    RegistryKey myKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\VisualStudio\\12.0\\SQLDB\\Database", true);
    if (myKey != null)
    {
        myKey.SetValue("QueryTimeoutSeconds", "0", RegistryValueKind.DWord);
        myKey.Close();
    }

    myKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\VisualStudio\\14.0\\SQLDB\\Database", true);
    if (myKey != null)
    {
        myKey.SetValue("QueryTimeoutSeconds", "0", RegistryValueKind.DWord);
        myKey.Close();
    }

    myKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\VisualStudio\\15.0\\SQLDB\\Database", true);
    if (myKey != null)
    {
        myKey.SetValue("QueryTimeoutSeconds", "0", RegistryValueKind.DWord);
        myKey.Close();
    }
}

private static void PublishDacpacSimple(string destinationServer, 
    string destinationDatabase, 
    string userID, 
    string password, 
    string publishFileFullPath, 
    string dacpacFileFullPath)
{
    string connectionString = BuildConnectionString(destinationServer, destinationDatabase, userID, password);

    XmlDocument xdoc = new XmlDocument();

    xdoc.Load(publishFileFullPath);

    DacServices ds = new DacServices(connectionString);
    using (DacPackage package = DacPackage.Load(dacpacFileFullPath))
    {
        var options = new DacDeployOptions();                
        
        options.CommandTimeout = 600;              

        ds.Message += (object sender, DacMessageEventArgs eventArgs) => Console.WriteLine(eventArgs.Message.Message);

        ds.Deploy(package, destinationDatabase, true, options);
    }
}

然后在 PowerShell 脚本中调用它:

$DacPacDeployerPath = """" + $scriptPath + "..\..\..\DacpacDeployUtility\bin\release\EBMDacpacDeployUtility.exe"""

$Output = Start-Process -FilePath $DacPacDeployerPath -ArgumentList $arguments -NoNewWindow -PassThru -Wait

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多