没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:黄竹雯|2019-06-11 14:37:18.240|阅读 553 次
概述:SQL数据库中的数据通常需要实时同步 - 可以通过检查一个数据库的更新然后将它们应用到另一个数据库来实现。在这种情况下,变更检测和同步过程应按计划自动运行,无需外部干预。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
SQL数据库中的数据通常需要实时同步 - 可以通过检查一个数据库的更新然后将它们应用到另一个数据库来实现。在这种情况下,变更检测和同步过程应按计划自动运行,无需外部干预。
Data Compare for SQL Server是一个外部工具,允许你比较SQL数据库,备份和脚本文件夹中的数据。使用dbForge Data Compare for SQL Server,你可以安排几乎实时的数据库同步。
你可以按照以下步骤设置该过程:
在“New Data Comparison(新建数据比较)”窗口中,在相应的选项卡中选择源数据库和目标数据库:
在“Mapping(映射)”选项卡中,你可以选择要比较的对象。此外,如果有必要,你可以指定键列和列表以进行比较:
完成比较后,你可以详细查看结果:
保存的项目(dcomp)文件将包含调度数据同步所需的所有对象和选项。
由于我们已经在Data Compare for SQL Server中成功测试了同步过程并保存了项目(dcomp)文件,因此我们可以使用PowerShell脚本自动执行该过程。
首先,我们需要创建一个函数来检查Outputs文件夹是否存在 - 它将用于存储带日期戳的输出摘要。我们希望确保保存每个同步的易于查找的应用程序日志,以防我们将来需要执行故障排除:
#checks if the Outputs folder exists. If it doesn’t, the script creates it and returns its full path function CheckAndCreateFolder($rootFolder, [switch]$Outputs) { $location = $rootFolder #set the location based on the used switch if($Outputs -eq $true) { $location += "\Outputs" } #create the folder if it doesn't exist and return its path if(-not (Test-Path $location)) { mkdir $location -Force:$true -Confirm:$false | Out-Null } return $location }
接下来,让我们定义的根文件夹和数据标记的输出摘要位置:
#set the root folder $rootFolder = "D:\DataSync\" #set the location of output files $outsLoc = CheckAndCreateFolder $rootFolder -Outputs
在本节中,我们定义应用程序的位置以及数据戳记变量。此外,我们定义包含应用程序参数的变量,例如:
以下脚本允许我们实现此目的:
#define the tool’s location, date stamp variable and the tool’s parameters $toolLocation = "C:\Program Files\Devart\dbForge Studio for MySQL\dbforgemysql.com" $dateStamp = (Get-Date -Format "Mmddyyyy_HHMMss") #output log file path $logPath = "$outsLoc\DataOutput_$dateStamp.txt" $Params = "/datacompare /compfile:""D:\DataSync\Project\test_DB_1vstest_DB_2.dcomp"" /log:""$logPath""" $sync = " /sync"
PowerShell脚本的下一部分将使用我们在上一步中说明的参数从其位置调用Data Compare。然后,定义返回代码变量:
#initiate the comparison of data sources (Invoke-Expression ("& `"" + $toolLocation +"`" " +$Params)) $returnCode = $LASTEXITCODE $message = ""
该脚本的最后一部分用于为三种可能的结果创建适当的响应:
if ($returnCode -notin (100, 101)) { #an error is encountered $logPath = "$outsLoc\DataOutput_error.txt" $message >> $logPath clear-content $logPath $message = "`r`n $returnCode - An error is encountered" #output file is opened when an error is encountered Invoke-Item "$logPath" } else{ if ($returnCode -eq 101) { clear-content $logPath (Invoke-Expression ("& `"" + $toolLocation +"`" " +$Params+$sync)) $returnCode = $LASTEXITCODE #schema changes are detected } if($returnCode -eq 0) { $message = "`r`n $returnCode - Schema changes were successfully synchronized" } else { #there are no schema changes if($returnCode -eq 100) { $message = "`r`n $returnCode - There are no schema changes. Job aborted" } } } $message >> $logPath
现在该作业已经自动化,可以按照你喜欢的任何方式进行调度 - 例如,在Windows Scheduler的帮助下进行。
一切准备就绪后,可以随时查看输出摘要。在此示例中,输出文件的位置由$ outsLoc变量定义,因此输出文件将保存到$ rootFolder \ $ outsLoc - 在此特定示例中,DataSync \ Outputs:
如果在执行脚本时发生错误,将显示错误消息以提供有关此错误的潜在原因的更多信息。此外,将创建包含错误详细信息的DataOutput_error.txt文件。
以下是完整的脚本:
#checks if the Outputs folder exists. If it doesn’t, the script creates it and returns its full path function CheckAndCreateFolder($rootFolder, [switch]$Outputs) { $location = $rootFolder #set the location based on the used switch if($Outputs -eq $true) { $location += "\Outputs" } #create the folder if it doesn't exist and return its path if(-not (Test-Path $location)) { mkdir $location -Force:$true -Confirm:$false | Out-Null } return $location } #set the root folder $rootFolder = "D:\DataSync\" #set the location of output files $outsLoc = CheckAndCreateFolder $rootFolder -Outputs #define the tool’s location, date stamp variable and the tool’s parameters $toolLocation = "C:\Program Files\Devart\dbForge Studio for MySQL\dbforgemysql.com" $dateStamp = (Get-Date -Format "Mmddyyyy_HHMMss") #output log file path $logPath = "$outsLoc\DataOutput_$dateStamp.txt" $Params = "/datacompare /compfile:""D:\DataSync\Project\ALLA1vsALLA2.dcomp"" /log:""$logPath""" $sync = " /sync" #initiate the comparison of data sources (Invoke-Expression ("& `"" + $toolLocation +"`" " +$Params)) $returnCode = $LASTEXITCODE $message = "" if ($returnCode -notin (100, 101)) { #an error is encountered $logPath = "$outsLoc\DataOutput_error.txt" $message >> $logPath clear-content $logPath $message = "`r`n $returnCode - An error is encountered" #output file is opened when an error is encountered Invoke-Item "$logPath" } else{ if ($returnCode -eq 101) { clear-content $logPath (Invoke-Expression ("& `"" + $toolLocation +"`" " +$Params+$sync)) $returnCode = $LASTEXITCODE #schema changes are detected } if($returnCode -eq 0) { $message = "`r`n $returnCode - Schema changes were successfully synchronized" } else { #there are no schema changes if($returnCode -eq 100) { $message = "`r`n $returnCode - There are no schema changes. Job aborted" } } } $message >> $logPath
如果在设置过程中出现任何问题或疑问,可以留言告诉我们。
感恩相伴16载,感恩答谢20万+新老用户,感恩相送三重钜惠好礼!限量产品优惠券等你来抢!
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@wqylolg.cn
在 Excel 工作表中,原始数据通常显示为缺乏直观性的普通数字。通过设置数字格式,可以将这些数字转换成更容易理解的形式。本文将介绍如何使用 Spire.XLS for .NET 通过 C# 设置 Excel 单元格中的数字格式 。
本文将演示如何使用 Spire.XLS for .NET 通过 C# 合并或取消合并 Excel 中的单元格。
Excel 文档的常规打印操作十分简单。然而,一旦涉及特殊打印需求,情况就会变得比较麻烦。文将介绍如何使用 Spire.XLS for .NET 在 C# 中通过页面设置对 Excel 打印选项进行设置,以及如何将 Excel 文档发送到打印机。
在本指南中,我们将向您展示如何免费在线旋转 PDF,并探索 Python、Java 和 C# 中的基于代码的方法。最后,您将了解最适合您需求的方法。
dbForge Data Compare for SQL Server是一个快速的、易于使用的Microsoft SQL Server数据库精确对比和同步数据的工具。它提供了扩展的用户映射功能,允许与SQL脚本和查询一起使用,呈现出一套强大的数据管理工具集。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@wqylolg.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢