Dacpac升级数据库时代有点傻

Fet*_*che 2 sql-server dac sql-server-data-tools

编辑:更新为状态它没有挂起,只需要年龄!

我正在尝试使用dacpac更新现有的sql server数据库.

我可以使用下面的(剥离)示例在30秒内创建一个新的SQL Server数据库.我遇到的问题是使用相同的dacpac,重新运行程序(因此它更新现有数据库而不是重新创建)需要20分钟.

如果时差到期是什么呢?全面使用了redgate的SqlCompare后,我觉得时间不容乐观.

部署方法的第三个参数是UpgradeExisting,我将其设置为true - 这是我需要做的还是我错过了什么?

void Deploy(string TargetConnectionString, string TargetDatabaseName, string pathToSourceDACPAC)
{

    DacServices dacServices = new DacServices(TargetConnectionString);

    //Set up message and progress handlers
    dacServices.Message += new EventHandler<DacMessageEventArgs>(dbServices_Message);
    dacServices.ProgressChanged += new EventHandler<DacProgressEventArgs>(dbServices_ProgressChanged);

    //Load the DACPAC
    DacPackage dacpac = DacPackage.Load(pathToSourceDACPAC);

    //Set Deployment Options
    DacDeployOptions dacOptions = new DacDeployOptions();
    dacOptions.AllowIncompatiblePlatform = true;

    //Deploy the dacpac
    dacServices.Deploy(dacpac, TargetDatabaseName, true, dacOptions);

}

//Event handlers...
void dbServices_Message(object sender, DacMessageEventArgs e)
{
    OutputThis("DAC Message", e.Message.ToString());
}

void dbServices_ProgressChanged(object sender, DacProgressEventArgs e)
{
    OutputThis(e.Status.ToString(), e.Message.ToString());
}
Run Code Online (Sandbox Code Playgroud)

注意,程序会在dacServices.Deploy行中消失到以太网中.

Fet*_*che 5

好的,在运行调试器(VS2012)时遇到了愚蠢的时间.编译完成后,在选择Memory DacSchemaModelStorageType时,时间为25秒左右,在选择File DacSchemaModelStorageType时,时间为45秒左右.

我想这只是意味着调试是一个痛苦的whatsit!

  • @Mark - 正如我上面提到的,检查您是否收到很多警告,因为所有 antlr 警告都是第一次机会异常,它们会暂停应用程序,将控制权传递给调试器(vs),调试器决定是中断还是继续 - 即使您有第一次机会异常被禁用,这就是你通过调试 API 得到的结果(Visual Studio 无法控制它)——如果有很多异常,这将是一个巨大的开销。 (2认同)