1

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
pika
  • 53
  • 2
  • 10
  • 1
    Take a look at the answer from @nawfal in this post: http://stackoverflow.com/questions/10540438/what-is-the-connection-string-for-localdb-for-version-11-- he covers checking the installation, checking that there is a LOCALDB instance and getting the connection string correct. – David Tansey Apr 09 '16 at 16:01

1 Answers1

0

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