Search code examples
sql-server-2008-r2iis-8.5database-mirroringautomatic-failover

Db fail over in Mirrored environment causing connection attempts from web app to fail until the application pool is restarted


I have a mirrored sql server db environment. A load balanced application hosted in IIS is accessing the databases. In Connection string I have mentioned FailOver partner. When I am performing fail over from db1 to db2 the application fails to connect.

The error that I received is:

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) at MyMethodName() at MyMethod() System.ComponentModel.Win32Exception (0x80004005): The network path was not found System.Data.SqlClient.SqlException (0x80131904): 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) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found.

Once I restart the application pool the application will be able to connect again to the db. My connection string would look like below.

<add name="SqlString" connectionString="Data Source=12.34.56.79,9100;Failover Partner=12.34.56.78,9100;Initial Catalog=test;Persist Security Info=True;User ID=####;Password=#####" />

I am using Sql server 2012, IIS 8.5, Windows Server 2012

Any help on this will be appreciated


Solution

  • I got this issue fixed after much research and taking help from many teams.

    It was found that the application was trying to connect to default port sql server 1433 on db fail over, even when the port number is specified in the connection string.

    Specified the alias in the both the application servers with port number using ClicConfig.exe

    This solution was provided by Microsoft.