SqlPackage.exe - "System.StackOverflowException"
SqlPackage.exe - "System.StackOverflowException"
我有一系列由 TFS 代理 运行 构建的 PowerShell 脚本,它们是构建过程的一部分。这些 运行 在 publish a series of DACPAC's to a given set of Databases. Recently I updated all the TFS build agents to the latest version(TFS 2018)
的几台服务器 (Windows Server 2012 R2) 上
今天我注意到我构建过程中的其中一台服务器不再 运行ning,特别是由于“System.WhosebugException”错误(非常适合这个网站)。
同样的问题可以通过手动 运行 运行 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\DAC0\SqlPackage.exe" -ArgumentList $arguments -NoNewWindow -PassThru -Wait
手工运行时,调试出的异常是:
An unhandled exception of type 'System.WhosebugException' occurred in Microsoft.SqlServer.TransactSql.ScriptDom.dll
我真的不确定此服务器上的什么配置会导致此类问题。资源方面,服务器非常强大,有大量可用内存,其他服务器 运行 就可以了。我试过各种版本的“SqlPackage”(13, 14),但似乎没有任何效果。我已经换掉了 DacPac,但这似乎也不起作用...
有人见过这个问题吗?什么样的服务器配置会导致此类问题?
更新 1:嗯,只需切换到新的“14.0”,“SqlPackage.exe”,现在我的所有机器上都安装了它,我想知道是否它与任何相关的 dll 有关,例如我在 SSDT.
中安装的那些
其实现在想想,我觉得这个问题是在我第一次安装VS 2017时在服务器上开始的,我想知道这对“SqlPackage.exe”有什么影响吗?
我也发现了这个interesting post,我想知道我是否可以通过这种方式解决它...
我从来没有想出如何为“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:
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
我有一系列由 TFS 代理 运行 构建的 PowerShell 脚本,它们是构建过程的一部分。这些 运行 在 publish a series of DACPAC's to a given set of Databases. Recently I updated all the TFS build agents to the latest version(TFS 2018)
的几台服务器 (Windows Server 2012 R2) 上今天我注意到我构建过程中的其中一台服务器不再 运行ning,特别是由于“System.WhosebugException”错误(非常适合这个网站)。
同样的问题可以通过手动 运行 运行 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\DAC0\SqlPackage.exe" -ArgumentList $arguments -NoNewWindow -PassThru -Wait
手工运行时,调试出的异常是:
An unhandled exception of type 'System.WhosebugException' occurred in Microsoft.SqlServer.TransactSql.ScriptDom.dll
我真的不确定此服务器上的什么配置会导致此类问题。资源方面,服务器非常强大,有大量可用内存,其他服务器 运行 就可以了。我试过各种版本的“SqlPackage”(13, 14),但似乎没有任何效果。我已经换掉了 DacPac,但这似乎也不起作用...
有人见过这个问题吗?什么样的服务器配置会导致此类问题?
更新 1:嗯,只需切换到新的“14.0”,“SqlPackage.exe”,现在我的所有机器上都安装了它,我想知道是否它与任何相关的 dll 有关,例如我在 SSDT.
中安装的那些其实现在想想,我觉得这个问题是在我第一次安装VS 2017时在服务器上开始的,我想知道这对“SqlPackage.exe”有什么影响吗?
我也发现了这个interesting post,我想知道我是否可以通过这种方式解决它...
我从来没有想出如何为“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:
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