连接到SQL Server时,网络或特定实例发生错误
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.
数据库的连接字符串:
<add name="RequirementContext"
connectionString="Data Source=RU-DEV24;Initial Catalog=OpenSoft.AgileAnalytics.EF;Integrated Security=True;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
我无法理解,这就是发生此错误的原因。求救!
错误的代码
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(),
};
}
}
!!!! 问题解决了。我刚刚将web.config文件添加到文件中:
<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>
答案 0 :(得分:1)
确保您的数据库引擎正在接受远程连接:
在SQL Server配置中启用TCP / IP:
确保SQL Browser服务正在运行:
配置Windows防火墙以允许访问:
答案 1 :(得分:0)
此错误的常见原因:
如果您使用的是SQL Express,则应该将“SQLEXPRESS”作为服务器的实例名称。