1

2 つの接続文字列を渡してスキーマの比較と更新を実行できるライブラリが .Net にあるかどうかを教えてください。

これが必要な理由は、さまざまな顧客のために複数のデータベースに展開するゴールデン データベースを維持しているためです。DBの更新があるたびにVSから手動でスキーマ比較を行う必要がある場合、長い時間がかかります。

すべてのクライアント接続文字列をループして、ゴールデン データベースと比較し、自動的に更新する予定です。

アドバイスしてください、ありがとう。

4

2 に答える 2

2

これが私がやったことです。非常に簡単な解決策です。必要な nuget ライブラリは以下のとおりです。検索してプロジェクトに含めます。

<package id="Microsoft.SqlServer.Dac" version="1.0.3" targetFramework="net45" />
<package id="Microsoft.SqlServer.DacFx.x86" version="130.3485.1" targetFramework="net45" />

以下はサンプルコードです。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Microsoft.SqlServer.Dac.Compare;

    namespace SchemaComparer
    {
        class Program
        {
            //The directory where all the scmp files are located
            const string schemaDirectory = "C:\SchemaCompare\\";

            static void Main(string[] args)
            {
                //Loop thru all the scmp from the directory. This set to max 2 thread that run parallel and update together
                Parallel.ForEach(Directory.GetFiles(schemaDirectory), new ParallelOptions { MaxDegreeOfParallelism = 2 }, (file) =>   
                {
                    try
                    {
                        // Load comparison from Schema Compare (.scmp) file
                        var comparison = new SchemaComparison(file);

                        Console.WriteLine("Processing " + Path.GetFileName(file));
                        Console.WriteLine("Comparing schema...");

                        SchemaComparisonResult comparisonResult = comparison.Compare();

                        // Publish the changes to the target database
                        Console.WriteLine("Publishing schema...");

                        SchemaComparePublishResult publishResult = comparisonResult.PublishChangesToTarget();

                        Console.WriteLine(publishResult.Success ? "Publish succeeded." : "Publish failed.");
                        Console.WriteLine(" ");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                });

                Console.ReadLine();
            }
        }
    }

2017 年 11 月 3 日に編集 これを機能させるには、scmp ファイルを作成してディレクトリに保存する必要があることを忘れている可能性があります。私の場合は「C:\SchemaCompare\」です。プログラムはすべての scmp ファイルを取得し、比較と更新を行います。したがって、将来比較する必要がある追加のデータベースがある場合は、scmp を作成してディレクトリに保存してください。

于 2017-04-24T01:45:15.043 に答える
0

Devart には、コマンド ラインの自動化をサポートするスキーマ比較ツールがいくつかあり、必要なことを実行できる可能性があります: https://www.devart.com/dbforge/sql/schemacompare/

于 2016-11-22T07:53:25.453 に答える