【发布时间】:2016-04-09 12:08:52
【问题描述】:
当我使用 asp.net mvc 运行我的 Web 应用程序时,我收到此错误:
“/”应用程序中的服务器错误。
在建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:SQL 网络接口,错误:26 - 定位服务器/实例时出错
错误来源:
var 结果 = 等待 UserManager.CreateAsync(user, model.Password);
我的web.config:
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApplication23-20160409124123.mdf;Initial Catalog=aspnet-WebApplication23-20160409124123;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
连接数据库
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
dans CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
}
我是否安装了 SqlLOcalDB?你能帮我吗?
【问题讨论】:
-
看看@nawfal 在这篇文章中的回答:stackoverflow.com/questions/10540438/… 他涵盖了检查安装、检查是否存在 LOCALDB 实例以及获取正确的连接字符串。
标签: sql sql-server asp.net-mvc localdb