即使完全访问(Dynamics CRM),SqlConnection也无法打开

时间:2015-06-08 11:19:29

标签: database sqlconnection datareader dynamics-crm-2015

我正在使用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执行此操作。

0 个答案:

没有答案