我正在使用SQlPackage.exe部署/发布数据库项目。我想在单独的日志文件中记录发布活动,如创建数据库/表或任何修改。但在sqlpackage.exe中似乎没有记录此信息的选项
其次,如果我以某种方式在这两者之间停止了sqlpackage部署(因为我使用的是bat文件,并从那里调用sqlpackage.exe命令),那么它不会回滚所有更改。
注意:我已经启用了包括跨国脚本选项。通过启用此选项,部署后脚本将不在事务块中。换句话说,如果在事务后脚本中有错误,但在模式中没有错误,那么模式部分将得到正确部署,这将在部署后脚本中抛出错误。因此,我的数据库处于不一致状态。我的观点是,如果有任何错误,它也应该回滚所有内容。
发布于 2016-03-25 15:36:43
您还可以从C#调用SqlPackage.exe并将其包装在ProcessStartInfo中(即从C#中执行外壳命令。我从堆栈溢出的其他地方获得了这段代码,并修改了它,以便在发生错误时执行Console.ReadLine(),并且我们处于调试模式;假设您传递的命令是SqlPackage.exe;然后您可以将错误消息更改为红色并暂停控制台窗口:
public void ExecuteCommandSync(object command, string message)
{
Console.WriteLine(message);
Console.WriteLine("------------------------------------------------------------------- ");
Console.WriteLine(" ");
Console.WriteLine("Executing command: " + command);
Console.WriteLine(" ");
Console.WriteLine("------------------------------------------------------------------- ");
Console.WriteLine(" ");
// create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows,
// and then exit.
var procStartInfo = new ProcessStartInfo("cmd", "/c " + command)
{
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
// Do not create the black window.
// Now we create a process, assign its ProcessStartInfo and start it
var proc = new Process { StartInfo = procStartInfo };
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.Start();
// Get the output into a string
var result = proc.StandardOutput.ReadToEnd();
string err = proc.StandardError.ReadToEnd();
// write the error and pause (if DEBUG)
if (err != string.Empty)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(err);
Console.ResetColor();
#if DEBUG
Console.WriteLine("Press enter to continue...");
Console.ReadLine();
#endif
}
proc.WaitForExit();
// Display the command output.
Console.WriteLine(result);
Console.WriteLine(" ");
Console.WriteLine("------------------------------------------------------------------- ");
Console.WriteLine(" ");
Console.WriteLine("Finished executing command: " + command);
Console.WriteLine(" ");
Console.WriteLine("------------------------------------------------------------------- ");
Console.WriteLine(" ");
}https://stackoverflow.com/questions/23928594
复制相似问题