需求
将A服务器的sql server数据库item_mst表的数据同步到MySQL数据库Part表
监控Item_mst表中item,description,overview 的更改并同步到MySQL数据库
针对需求一,基本就是执行一次,单独写了个winform用来做这事
针对需求二,写了个Windows service app
Nuget安装
Dapper就是个orm
Serilog用来记log
SQLTableDependency用来检测表的改动,文档地址:https://github.com/christiandelbianco/monitor-table-change-with-sqltabledependency
使用这个别忘了执行 alter database [] set enable_broker with rollback immediate;
创建service
添加安装程序
如何安装service
Create a Windows service app
https://docs.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer
How to: Add Installers to Your Service Application
https://docs.microsoft.com/zh-cn/dotnet/framework/windows-services/how-to-add-installers-to-your-service-application
How to: Install and uninstall Windows services
https://docs.microsoft.com/en-us/dotnet/framework/windows-services/how-to-install-and-uninstall-services
源码
目录结构
Models文件夹里的ItemMst.cs文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SyncItemMstAllService.Models
{
/// /// table name: item_mst
/// note: We do not need to specify all table columns but just the ones we are interested:
///
public class ItemMst
{
// internalNumber
public string Item { get; set; }
// name
public string Description { get; set; }
// description
public string Overview { get; set; }
}
}