0

SqlConnection を使用して、C# コンソール アプリから MS Dynamics CRM DB からデータを読み取っています。

ソースと宛先があります (ソースは CRM 2011 で、宛先は CRM 2015 です)。ソースは正常に機能しますが、宛先は機能しません。両方に対して同様の接続文字列を宣言し、ConnectionString を使用して新しい SqlConnection を実行してから、SqlConnection.Open を実行します。

var fromSql = "Data Source=someSql014 ;Initial Catalog=CRM2011Dev_MSCRM;Integrated Security=True";
var toSql = "Data Source=someSql014\tst ;Initial Catalog=CRM2015Dev_MSCRM;Integrated Security=True";

var SourceConnectionString = FromSql;
using (var SourceConnection = new SqlConnection(SourceConnectionString))
{
    SourceConnection.Open();
    using (var command = new SqlCommand(selectQuery, SourceConnection))
    {
        var i = 0;
        var reader = command.ExecuteReader();
        while (reader.Read())
        {
            .......

宛先に対してこれを行う場合にのみ、エラーが発生します。

A network-related or instance-specific error occurred while establishing a connection to SQL
Server. The server was not found or was not accessible. Verify that the instance name is
correct and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Inner Exception: {"The network path was not found"}

もう 1 つの問題は、サーバーからプログラムを実行したいのですが、コードをサーバーに移動してそこから実行しようとすると、ソース接続でさえ問題が発生することです。実行中に例外は発生しませSqlConnection.Openんが、DB から何も読み取られません。while (reader.Read())ブロックをスキップするだけですが、そうすべきではありません。(SELECTクエリは問題ありません)

注:データベース(両方)に接続して読み取るためのフルアクセスがあり、サーバーとローカルマシンのSQL Management Studioからアクセスできます。

4

0 に答える 0