mysql后台修改表_C# 后台服务监控SQL Server数据库表改动并同步到MySQL数据库表

需求将A服务器的sql server数据库item_mst表的数据同步到MySQL数据库Part表监控Item_mst表中item,description,overview 的更改并同步到MySQL数据库针对需求一,基本就是执行一次,单独写了个winform用来做这事针对需求二,写了个Windows service appNuget安装 Dapper就是个ormSerilog用来记logSQLTa...
摘要由CSDN通过智能技术生成

需求

将A服务器的sql server数据库item_mst表的数据同步到MySQL数据库Part表

监控Item_mst表中item,description,overview 的更改并同步到MySQL数据库

针对需求一,基本就是执行一次,单独写了个winform用来做这事

针对需求二,写了个Windows service app

Nuget安装

fa7a89cc5f645428d11b7ee1911ccc1b.png

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

源码

目录结构

8246e73f9fb95b1b1a4c4bc9ee83405d.png

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; }

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值