locked
Unable to open connection RRS feed

  • Question

  • Hi,

    I've a web application that needs to connect to SQL Server Database. When i browse localhost via IIS, the web browser successfully open all the tables structures stored in Web Service... but as soon as I invoke to fetch data from database, it fails every time.

    I've checked the configuration for application in IIS and is same on another computer where it works fine with similar SQL Server database. I've also checked Instance/Server options on SQL Server and it seems to allow remote connections and both SQL Server and Windows Authentication are allowed. Permissions on the SQL database seems to be correct, at least as what I know, and other ODBC applications are able to connect with same database fine.

    Could someone guide me where I'm doing wrong please?? I'm really desperate for solution on this please. Google search does return some results but none of them I tried is solving my problem.
    I'm posting the message below that appears on web browser. Beginning and near the end of text below might be useful to understand the correct cause.

    P.S. I feel this is the closed forum where I could post this question. If I'm still posting in a wrong forum, please help me direct to the correct one.

    Thanks

    System.Data.SqlClient.SqlException: 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.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)
       at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
       at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
       at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData)
       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, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()
       at Service.GettblCountries() in c:\AccessWS\App_Code\Service.cs:line 922


    • Edited by KhurramKZ Tuesday, October 17, 2017 2:46 PM
    Tuesday, October 17, 2017 2:42 PM

Answers

All replies

  • This is a plain-vanilla connection error for which there can be lots of reasons, including not spelling the server name properly.

    Here is a troubleshooter you can try: https://docs.microsoft.com/en-us/sql/relational-databases/tutorial-getting-started-with-the-database-engine


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    • Marked as answer by KhurramKZ Wednesday, October 18, 2017 5:22 AM
    Tuesday, October 17, 2017 8:26 PM
  • Hi KhurramKZ,

    Per the error messages above, it seems to be Connectivity errors. Based on this, you may try the following articles.

    Reference: Solving Connectivity errors to SQL Server

                      ODBC Error

    Best Regards,

    Will

          


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 18, 2017 3:21 AM
  • Yes I understand it is plain-vanilla connectivity issue but I was not getting the cause. Thanks for the linked, i followed step by step and it turned out that I didn't enable Browser Service. Feeling stupid :/

    Thanks for the help.

    Wednesday, October 18, 2017 5:24 AM