0

我正在使用 SqlConnection 从 C# 控制台应用程序中读取 MS Dynamics CRM 数据库中的数据。

我有一个源和目标(源是 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"}

另一个问题是我们想从服务器运行程序,但是如果我们将代码移动到服务器并尝试从那里运行它,即使源连接也会出现问题。在 期间它不会给出任何异常SqlConnection.Open,但它根本不会从数据库中读取任何内容。它只会跳过while (reader.Read())不应该的块。(SELECT查询没问题)

注意:我拥有连接和读取数据库(两者)的完全访问权限,并且可以从服务器和本地计算机上的 SQL Management Studio 执行此操作。

4

0 回答 0