Reader Level:
Articles

No connection could be made because the target machine actively refused it

By Mahesh Chand on Apr 26, 2012
Fix for error no connection could be made because the target machine actively refused it.
  • 0
  • 0
  • 19439

No connection could be made because the target machine actively refused it

You may get this error while trying to establish a connection to a SQL Server database remotely. Here are a few things you should check.

  • Make sure your server name is correct.
  • Make sure database server is up and running. You can see MSSQLSERVER service or whatever is your SQL Server instance name is running.
  • Try to ping your server name and see if IP is correct.
  • Ping the IP address and see it is resolving.
  • If your server is behind firewall, you may want to add a port number to your connection string. Port 1433 is the default port for SQL Server.

By default, SQL Server uses port number 1433. To create a connection string over firewall with the IP and port number, use the following format:

<add name="connection" connectionString="Data Source=[YOURIP XX.XX.XX.XX],1433;Network Library=DBMSSOCN;Initial Catalog=[YOURDBNAME];User ID=[YOURUSERID];Password=[YOURPASSWORD]"/>

You need to make sure you replace variables in this connection string with correct values.

 

Mahesh Chand

C# Corner founder, 10-times Microsoft MVP, technical author, and software architect. Mahesh authored his first book, A Programmer’s Guide to ADO.NET in C# with APress at the age of 25. C# Corner is a memb... Read more

COMMENT USING