Toolkit Samples + SQL Express 2005 = Watch Connection Errors

dandradedandrade Posts: 10
edited October 31, 2007 3:01PM in SQL Toolkit Previous Versions
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.

Comments

Sign In or Register to comment.