1

When connecting to SQL Server error occurred with the network or to a specific instance

The server was not found or is not available.
Verify that the instance name is spelled correctly 
and that SQL Server allow remote connections. 

provider: SQL Network Interfaces, error: 26 - 
Error detection specified server or instance.

The connection string to the database:

<add name="RequirementContext" 
    connectionString="Data Source=RU-DEV24;Initial Catalog=OpenSoft.AgileAnalytics.EF;Integrated Security=True;MultipleActiveResultSets=True"
    providerName="System.Data.SqlClient" />

I can not understand, which is why this error occurs. Help please!

Code in which an error

public class Permission
    {
        public string RoleString
        {
            get
            {
                return string.Join(", ", UserRoles);
            }
        }

        public int UserId { get; set; }

        public string UserName { get; set; }

        public List<string> UserRoles { get; set; }

        public static Permission CreateFromUserProfile(UserProfile userProfile)
        {
            //here
            return new Permission
            {
                UserId = userProfile.UserId,
                UserName = userProfile.UserName,
                UserRoles = Roles.GetRolesForUser(userProfile.UserName).ToList(),
            };
        }
    }

!!!! The problem was solved. I just added to file web.config this code:

<roleManager enabled="true" defaultProvider="SimpleRoleProvider">
      <providers>
        <clear />
        <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider,WebMatrix.WebData" />
      </providers>
    </roleManager>
    <membership defaultProvider="SimpleMembershipProvider">
      <providers>
        <clear />
        <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
      </providers>
    </membership>

2 Answers2

2

Make sure that your database engine is accepting remote connections:

  • Start > All Programs > SQL Server 2012 > Configuration Tools > SQL Server Surface Area Configuration
  • Click on Surface Area Configuration for Services and Connections
  • Select the instance that is facing the problem > Database Engine > Remote Connections
  • Enable local and remote connections
  • Restart the instance

Enable TCP/IP in SQL Server Configuration:

  • Go to Start > All Programs > Microsoft SQL Server 2012 > Configuration Tools > SQL Server Configuration Manager > Select TCP/IP.
  • Right click and select enable

Make sure that the SQL Browser service is running:

  • On the Start menu, right-click My Computer, and then click Manage.
  • In Computer Management, expand Services and Applications, and then click Services.
  • In the list of services, double-click SQL Server Browser.
  • In the SQL Server Browser Properties window, click Start or Stop. When the service starts or stops, click OK.

Configure your windows firewall to allow access :

  • On the Start menu, click Run, type WF.msc, and then click OK.
  • In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound Rules, and then click New Rule in the action pane.
  • In the Rule Type dialog box, select Port, and then click Next.
  • In the Protocol and Ports dialog box, select TCP. Select Specific local ports, and then type the port number of the instance of the Database Engine, such as 1433 for the default instance. Click Next.
  • In the Action dialog box, select Allow the connection, and then click Next.
  • In the Profile dialog box, select any profiles that describe the computer connection environment when you want to connect to the Database Engine, and then click Next.
  • In the Name dialog box, type a name and description for this rule, and then click Finish.
skywalker2909
  • 1,636
  • 2
  • 31
  • 46
  • I have consistently done everything that you have written. Unfortunately, the same error in the same place in the code – Татьяна Друзенко Jan 22 '15 at 14:13
  • look at the last part of my answer and perform those steps and see if that helps – skywalker2909 Jan 22 '15 at 14:20
  • Unfortunately, recent actions also did not help in solving the problem. There is the same error. – Татьяна Друзенко Jan 23 '15 at 08:30
  • @ТатьянаДрузенко - i would suggest you uninstall sql server and perform a fresh clean install once again, and after that please go through all these links - 1> http://www.linglom.com/it-support/enable-remote-connection-on-sql-server-2012-express/ , 2> http://www.codeproject.com/Questions/335874/A-network-related-or-instance-specific-error-occur , 3> http://serverfault.com/questions/601317/cant-connect-to-sql-sever-management-express-2012, 4> http://sevennet.org/2014/11/24/how-to-enable-remote-connections-for-sql-server-express-2012/, 5> http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=195517 – skywalker2909 Jan 23 '15 at 08:35
  • I think that the problem is not in the sql server. All data from the database and displayed on the pages only an error in the method. Everything else works fine. – Татьяна Друзенко Jan 23 '15 at 08:40
  • Okay, on which line in your code does the error occur? – skywalker2909 Jan 23 '15 at 08:47
  • //here return new Permission { UserId = userProfile.UserId, UserName = userProfile.UserName, UserRoles = Roles.GetRolesForUser(userProfile.UserName).ToList(), }; Last method – Татьяна Друзенко Jan 23 '15 at 08:57
  • Error here: UserRoles = Roles.GetRolesForUser(userProfile.UserName).ToList() – Татьяна Друзенко Jan 23 '15 at 09:41
  • Glad , you got the solution, there is also an other solved question somewhat similar to yours on stackoverflow http://stackoverflow.com/questions/14521003/mvc4-userisinrole-unable-to-connect-to-sql-server-database – skywalker2909 Jan 24 '15 at 20:47
0

Common causes of this error:

  1. The server named in the connection string doesn't exist (misspelled, etc.)
  2. Server is unavailable (off-line, etc.)
  3. Server is unreachable (try pinging the hostname to verify these first 3)
  4. Server is not configured to allow network access
  5. Windows Firewall (or other security software) is blocking access to the SQL Server port
  6. SQL Server instance name not specified or incorrect (in the example above, the connection would fail unless you're using the default instance on your sever)

If you're using SQL Express, you should probably have "SQLEXPRESS" as the instance name for your server.

The Mad Coder
  • 161
  • 1
  • 3
  • 1. pinging the hostname: connection to the server passes 2. All data are derived from the tables on pages, then the name is spelled correctly. The error code at this point: `code`public static Permission CreateFromUserProfile(UserProfile userProfile) { return new Permission { UserId = userProfile.UserId, UserName = userProfile.UserName, UserRoles = Roles.GetRolesForUser(userProfile.UserName).ToList(), }; }`code` – Татьяна Друзенко Jan 22 '15 at 13:42