0
votes

I published my site on plesk, in login form when I enter username and password I get error. I should say that my login form is based on asp.net configuration and roles and users are set there.

System.Data.SqlClient.SqlException (0x80131904): 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: SQL Network Interfaces, error: 26 Error Locating Server/Instance Specified)

at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.Open() at System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) at System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) at System.Web.Security.SqlRoleProvider.GetRolesForUser(String username) at System.Web.Security.Roles.GetRolesForUser(String username) at RealEstate.login.Button1_Click(Object sender, EventArgs e) in C:\Users\EZ-TECH\Documents\Visual Studio 2010\Projects\3Layer\RealEstate\RealEstate\login.aspx.cs:line 36 ClientConnectionId:00000000-0000-0000-0000-000000000000 Error Number:-1,State:0,Class:20

3
Have you updated the database connection string for connecting to server database?Mohsin Mehmood
yes I have a connectionstring in my web.configkasra melk
Verify that connection string is correct and you are able to connect to sql server instance using the credentials provided in connection string. Note that mostly you have to update connection string when application is published on the set serverMohsin Mehmood

3 Answers

1
votes

There could be several issues causing your error:

1) Make sure your server name is correct, e.g., no typo on the name.

2) Make sure your instance name is correct and there is actually such an instance on your target machine. [Update: Some application converts \ to . If you are not sure about your application, please try both ServerInstance and Server\Instance in your connection string]

3) Make sure the server machine is reachable, e.g, DNS can be resolve correctly, you are able to ping the server (not always true). Simply open Command Prompt and type "-ping yourservername" if it is a named instance or "-ping yourserverIP" if it is an unnamed instance.

4) Make sure SQL Browser service is running on the server.

5) If firewall is enabled on the server, you need to put sqlbrowser.exe and/or UDP port 1434 into exception.

I had the same issue with an application of mine and it was resolved by 4), enabling the SQL Browsing service on the server.

Reference and additional information: https://blogs.msdn.microsoft.com/sql_protocols/2007/05/13/sql-network-interfaces-error-26-error-locating-serverinstance-specified/

1
votes

I had same error, I later figured out that I was using a forward slash (/) instead of backslash (\) slash in my connection string.

This was what I was using-:

Server=(localdb)//mssqllocaldb;

While this was the correct connection string:

Server=(localdb)\\mssqllocaldb;
0
votes

In my case it was intermmitent error, on and off. It was caused by DB server having IP conflict. Hope this will help somebody.