[英]Unable to establish a connection to a database of SQL Server
連接到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>
確保您的數據庫引擎正在接受遠程連接:
在SQL Server配置中啟用TCP / IP:
確保SQL Browser服務正在運行:
配置Windows防火牆以允許訪問:
導致此錯誤的常見原因:
如果您使用的是SQL Express,則可能應使用“ SQLEXPRESS”作為服務器的實例名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.