Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I am having a web application in asp.net 4.0 where I implemented custom membership and role providers. whenever I am opening the app homepage, it connects to the database and gets some information. There is also a login form and when I am logging in, it validates the user through the database and redirects me to the reserved pages but then this error is appearing:

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.

Here are my connectionstrings:

<connectionStrings>
  <clear/>
  <remove name="LocalSqlServer"/>
     <add name="LocalSqlServer" connectionString="Data Source=MSSQL2008-1;Initial Catalog=agency;
        Integrated Security=False;User ID=adis_agency;Password=niarda2012;Connect Timeout=180;Encrypt=False;
        Packet Size=4096" providerName="System.Data.SqlClient" />
     <add name="AgencyConn" connectionString="Data Source=MSSQL2008-1;Initial Catalog=agency;
        Integrated Security=False;User ID=adis_agency;Password=niarda2012;Connect Timeout=180;Encrypt=False;
        Packet Size=4096" providerName="System.Data.SqlClient"/>
</connectionStrings>

Following are also the membership and role manager web.config section:

<membership defaultProvider="AuthProvider">
  <providers>
    <clear/>
      <add name="AuthProvider" type="AuthenticationProvider" applicationName="~/Reserved/" connectionStringName="AgencyConn"/>
  </providers>
</membership>
<roleManager enabled="true" defaultProvider="MyRoleProvider">
  <providers>
    <clear/>
      <add name="MyRoleProvider" type="RoleAccessProvider" connectionStringName="AgencyConn"/>
  </providers>
</roleManager>

Can anyone help with where I'm going wrong?

1 Answer

0 votes
by (12.7k points)

If you are connecting from the Windows machine A to the Windows machine B (server with the SQL Server installed), and are getting this error, you have to do the following:

On machine B:

1.) Turn on the Windows service called the "SQL Server Browser" and then start the service

2.) Then In the Windows firewall, enable the incoming port UDP 1434 (in case if the SQL Server Management Studio(SSMS) on machine A is connecting or a program on the machine A is connecting)

3.) Again In the Windows firewall, enable incoming port TCP 1433 (in case there is a telnet connection)

4.) And in the SQL Server Configuration Manager, enable TCP/IP protocol for port 1433.

enter image description here

Want to know more about SQL ? Join this SQL Certification course by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 22, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...