Unable to establish a connection to a database of SQL Server

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>

Upvotes: 1

Views: 6456

Answers (2)

skywalker2909
skywalker2909

Reputation: 1686

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.

Upvotes: 2

The Mad Coder
The Mad Coder

Reputation: 161

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.

Upvotes: 0

Related Questions