0

I'm reading data from a MS Dynamics CRM DB from a C# console app using a SqlConnection.

I have a source and destination (source is CRM 2011 and destination is CRM 2015) source works fine but destination does not. I've declared similar connection strings for both of them and do a new SqlConnection using the ConnectionString and then do 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())
        {
            .......

Only when doing this for destination I get an error:

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

Another issue is that we want to run the program from a server, but if we move the code to a server and try to run it from there, even the source connection gets problems. It won't give any exception during SqlConnection.Open, but it will simply not read anything from the DB. It will just skip past the while (reader.Read()) block, which it shouldn't. (SELECT query is fine)

Note: I have full access to connect and read from the databases (both of them) and can do so from SQL Management Studio on server and local machine.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
  • Okay the .Open failed because I had only one backslash in the connection string. But why it won't retrieve any data even though when it runs from server is still a mystery. It retrieves it just fine in SQL management studio.. – user3384242 Jun 08 '15 at 11:41
  • What objects do you use in your queries? Tables, filtered views? – Henk van Boeijen Jun 09 '15 at 14:18

0 Answers0