locked
provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) RRS feed

  • Question

  • User-605499000 posted

    Hi 

    Below is the error message and also the web config.  I am using visual studio 2019 as.net c#.  I had to upgrade the sql and they changed the Jen19.mdf to Jen19.mdf1. Should I delete the old mdf and change the new one to just mdf.  Also in the old web config they had a line listing the SQl and there was a mdf listed. I don't have that in the new web config.  Should I? The mdf1 file has the products listed in it.  

    Thanks, Jen

    Server Error in '/' Application.


    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)

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: 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)

    Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Web config:

    <?xml version="1.0" encoding="utf-8"?>
    <!--
    For more information on how to configure your ASP.NET application, please visit
    https://go.microsoft.com/fwlink/?LinkId=169433
    -->
    <configuration>
    <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>
    <system.web>
    <compilation debug="true" targetFramework="4.7.2" />
    <httpRuntime targetFramework="4.7.2" />
    <pages>
    <namespaces>
    <add namespace="System.Web.Optimization" />
    </namespaces>
    <controls>
    <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
    </controls>
    </pages>
    <customErrors mode="Off" defaultRedirect="ErrorPage.html">
    </customErrors>
    <profile defaultProvider="DefaultProfileProvider">
    <providers>
    <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
    </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
    <providers>
    <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
    </providers>
    </membership>
    <roleManager defaultProvider="DefaultRoleProvider">
    <providers>
    <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
    </providers>
    </roleManager>
    <!--
    If you are deploying to a cloud environment that has multiple web server instances,
    you should change session state mode from "InProc" to "Custom". In addition,
    change the connection string named "DefaultConnection" to connect to an instance
    of SQL Server (including SQL Azure and SQL Compact) instead of to SQL Server Express.
    -->
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
    <providers>
    <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
    </providers>
    </sessionState>
    </system.web>
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
    <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
    </dependentAssembly>
    </assemblyBinding>
    </runtime>
    <entityFramework>
    <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    <parameters>
    <parameter value="mssqllocaldb" />
    </parameters>
    </defaultConnectionFactory>
    </entityFramework>
    <connectionStrings>
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-Jen19-20190804123356;Integrated Security=SSPI" />
    </connectionStrings>
    <system.codedom>
    <compilers>
    <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
    <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
    </system.codedom>
    </configuration>

    Tuesday, August 20, 2019 5:07 PM

Answers

  • User-605499000 posted

    Thank you very much for all of your help. I went over all of your checks and then called up the server that is hosting my site. They had not updated the database. They were still using the 2008 database. I am in the process of updating everything and I should be fine.  I should have checked them first as I have had problems with them the last couple of weeks.  But, I thought everything had been settled and I have used them since 2009.

    Again, I can't thank all of you for your help. I am not a programmer and I have learned so much from everyone.

    Jen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 27, 2019 12:32 AM

All replies

  • User-719153870 posted

    Hi bumples18,

    bumples18

    <connectionStrings>
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-Jen19-20190804123356;Integrated Security=SSPI" />
    </connectionStrings>

    bumples18

    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)

    As the error message said, this error might be caused by wrong server name or instance name.

    To solve this issue, you can refer to this article.

    In this article, are below several steps to solve the problem:

    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]

    For above two steps, you can refer to query instance name and sqlconnection.

    Use 

    select @@servicename --Instance name
    select @@ServerName --server name

    Also please refer to sql express instance name.

    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). 

    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.

    Also in this article, you can rule out possiblity 4) and 5) above with a tool you can find in the [Update May 2009].

    As for the mdf1, you can refer to what is mdf1 file, where you can find it's a backup.

    Best Regard,

    Yang Shen

    Wednesday, August 21, 2019 1:52 AM
  • User665608656 posted

    Hi bumples,

    According to your description,  the reasons for throwing this issue could be wrong server name, disabled remote connection and firewall blocking.

    You can follow the steps below to solve this issue, you can also refer to this link : provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified

    1.Check the server on which SQL Server is running can be accessible. You can use ping command to test that. For instance, ping <computer_name> or ping <IP_address>.

    The ping command may be block by the firewall, make sure ICMP is enabled in the firewall, you can refer to this link: Windows Firewall Quick Fixes

    2. Choose appropriate protocol.

    3. Configure Windows firewall accordingly based on what protocol you have chosen to use. For detailed information about how to configure Windows Firewall to allow SQL Server, please check  Configure the Windows Firewall to Allow SQL Server Access

    4.Enable SQL Server Browser Services

    You need to enable SQL Server Browser Services if the following are both true:

    • SQL Server is not listening on default 1433 port or not use default pipe name \\.\pipe\sql\query;
    • The corresponding TCP port or pipe name is not specified in the connection string (such as Srv1\SQL2008, 1500).

    If you have enabled SQL Server Browser Services, you still need to open UDP 1434 port which is used by Browser Services in the Windows firewall.

    You can also refer to this link : SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified

    Best Regards,

    YongQing.

    Thursday, August 22, 2019 6:25 AM
  • User-605499000 posted

    Thanks for your response. I have checked everything and it is all fine. I did a test connection and it said it was working.  I have read all your suggestions. I am using SQLmanagement  18.2 and they have made a lot of changes so a lot of what I read is much older.  Should I be using SQL authentication or windows. I am using windows.

    Do you think that it is the server that I am using to load my project?  

    Thanks, Jen

    Friday, August 23, 2019 8:27 AM
  • User-605499000 posted

    I got into the config file and fixed that and the firewall but still have a problem. In the administration of my computer I went to services and then SQlServerEspress and tried to restart it and it did not work. Also the same for the SQLbrowser.  I don't know what I did wrong. I followed a youtube person that showed me how to get rid of the 26 error. It did not work.  Where do I go from here. Any ideas

    Jen

    Friday, August 23, 2019 10:11 PM
  • User-719153870 posted

    Hi Jen,

    I know you have checked a lot, but there's an error there must be something wrong. Thus, we need to check more to see where the problem is.

    1. Check whether the server name or alias of SQL server is set correctly.
    2. Check whether TCP/IP protocol is enabled on the client side and SQL server side.
    3. Make local connection first to determine whether the problem is SQL server itself or the network layer.
    4. Check whether the SQL server Browser service of SQL server starts normally if it is a named istance.
    5. Examine the SQL Server error log for messages confirming that SQL is listening on the expected network interfaces and ports.
    6. Ping the IP address of the server where SQL server is installed to see if it works, and test whether the port number of SQL server listening is enabled.
    7. If step6 fails, check the firewall configuration to see whether the corresponding port number is opened in the firewall.

         8. Check whether the local connection and maximum connection Numbers are set. Which you can refer to below:

    Best Regard,

    Yang Shen

    Monday, August 26, 2019 6:04 AM
  • User-605499000 posted

    Thank you very much for all of your help. I went over all of your checks and then called up the server that is hosting my site. They had not updated the database. They were still using the 2008 database. I am in the process of updating everything and I should be fine.  I should have checked them first as I have had problems with them the last couple of weeks.  But, I thought everything had been settled and I have used them since 2009.

    Again, I can't thank all of you for your help. I am not a programmer and I have learned so much from everyone.

    Jen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 27, 2019 12:32 AM