简体   繁体   中英

Can't establish a connection to SQL Server LocalDB

When I run my web application using asp.net mvc, I get this error :

Server Error in '/' Application.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance

error source :

var result = await UserManager.CreateAsync(user, model.Password);

My 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>

Connection to the database

 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();
    }
}

Have I installed SqlLOcalDB? Can you help me please?

I have resolved my problem ! @Gonzalo Lucero 's solution fixed my problem How to add LocalDB to Visual Studio 2015 Community's SQL Server Object Explorer? !!thank you very much for your efforts guys !! I 'm so grateful.

When all else fails and you don't care about data loss, delete and recreate your LocalDB\\YourDbName database! At the command prompt

sqllocaldb delete YourDbName sqllocaldb create YourDbName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM