Toolkit Samples + SQL Express 2005 = Watch Connection Errors

Forum for users of SQL Toolkit 3,4,and 5

Toolkit Samples + SQL Express 2005 = Watch Connection Errors

Postby dandrade » Fri Oct 26, 2007 10:17 pm

Unhandled Exception: System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)

The error above is documented by MS as a firewall problem. However, I followed KB instructions and error persist. There is no such problem. I ran samples fine. Just had to use proper connection strings. Sample apps assume default instance name and use a dot (.) You can see in CompareTwoDatabases this lines

widgetStaging.Register(new ConnectionProperties(".", "WidgetStaging"), Options.Default);
widgetProduction.Register(new ConnectionProperties(".", "WidgetProduction"), Options.Default);

I tested sample apps using different server names, including the use of port number SQL listens too. Initially I had connection errors. However, I had a similar problem in another app that gave me a clue. In SQL Express instances may have to be referenced like this: SERVERNAME\\instancename

So, this is how I modified sample app:

VB.NET
widgetStaging.Register(New ConnectionProperties("SERVERNAME\\INSTANCENAME", "WidgetStaging", "username", "password"), Options.Default)
widgetProduction.Register(New ConnectionProperties("SERVERNAME\\INSTANCENAME", "WidgetProduction", "username", "password"), Options.Default)

C#
widgetStaging.Register(new ConnectionProperties("SERVERNAME\\\\INSTANCENAME", "WidgetStaging", "username", "password"), Options.Default);
widgetProduction.Register(new ConnectionProperties("SERVERNAME\\\\INSTANCENAME", "WidgetProduction", "username", "password"), Options.Default);

NOTICE THAT IN C# I HAD TO USE DOUBLE SLASH, otherwise there is an error about unrecognized escape sequence.
dandrade
 
Posts: 6
Joined: Sun Sep 30, 2007 1:52 am

Postby chris.buckingham » Wed Oct 31, 2007 8:01 pm

Thank you for this tip - it is a common problem with slashes throughout a number of scripting languages - something that wasn't thought through in the early days.
Chris Buckingham
Red-Gate support
chris.buckingham
 
Posts: 56
Joined: Mon Jul 30, 2007 1:39 pm


Return to SQL Toolkit Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests