首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SqlPackage.exe - "System.StackOverflowException“

SqlPackage.exe - "System.StackOverflowException“
EN

Stack Overflow用户
提问于 2017-12-12 23:09:14
回答 1查看 479关注 0票数 0

我有一系列由TFS代理运行的PowerShell脚本,它们是构建过程的一部分。这些服务器运行在多个服务器(Windows 2012 R2)上,这些服务器是出版一系列DACPAC的对给定的数据库集运行的。最近,我将所有TFS构建代理更新为最新版本(2018年TFS)。

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

这个问题可以通过手动运行power shell脚本来再现,但是只有在这一台服务器上,所有其他服务器都没有问题地运行。脚本如下所示:

代码语言:javascript
复制
$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

手动运行时,调试的例外情况是:

System.StackOverflowException类型的未处理异常发生在Microsoft.SqlServer.TransactSql.ScriptDom.dll中

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

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

更新1:嗯,只需切换到新的"14.0","SqlPackage.exe“

实际上,现在我想到这个问题,我想这个问题是在我第一次安装VS 2017的时候在服务器上开始的,我想知道这对"SqlPackage.exe“有什么影响吗?

我也找到了这个有趣的帖子,我想知道我能不能这样做.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-21 15:24:24

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

代码语言:javascript
复制
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脚本中调用它:

代码语言:javascript
复制
$DacPacDeployerPath = """" + $scriptPath + "..\..\..\DacpacDeployUtility\bin\release\EBMDacpacDeployUtility.exe"""

$Output = Start-Process -FilePath $DacPacDeployerPath -ArgumentList $arguments -NoNewWindow -PassThru -Wait
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47783048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档