Red Gate forums :: View topic - Toolkit Samples + SQL Express 2005 = Watch Connection Errors
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Toolkit Previous Versions
SQL Toolkit Previous Versions forum

Toolkit Samples + SQL Express 2005 = Watch Connection Errors

Search in SQL Toolkit Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
dandrade



Joined: 30 Sep 2007
Posts: 6

PostPosted: Fri Oct 26, 2007 10:17 pm    Post subject: Toolkit Samples + SQL Express 2005 = Watch Connection Errors Reply with quote

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.
Back to top
View user's profile Send private message
chris.buckingham



Joined: 30 Jul 2007
Posts: 56

PostPosted: Wed Oct 31, 2007 8:01 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group