ca9163d9
ca9163d9

Reputation: 29159

Recreate LocalDB in the App_Data folder?

I replaced the auto-created aspnet-myproject-20130130223621.mdf and it's ldf files with the files from another project. It didn't work so I deleted these two files and hope the Asp.Net can re-create these two files. I always get the following error Exception in the following function.

  1. Is it possible to replace the auto-generated Sql server localDB files with existed database files?
  2. How to let Asp.net recreate these database files?

Exception on:

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    // Ensure ASP.NET Simple Membership is initialized only once per app start
    LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
}

Exception message:

{"Exception has been thrown by the target of an invocation."}

InnerException message:

{"Cannot attach the file 'c:\users\nick\documents\visual studio 2012\Projects\MyProject\MyProject\App_Data\aspnet-MyProject-20130130223621.mdf' as database 'aspnet-MyProject-20130130223621'."}

Upvotes: 1

Views: 2896

Answers (1)

Artless
Artless

Reputation: 4568

Open up your SQL Server Management studio and connect to LocalDB. You'll see that your Database is still there. Delete it from there and .NET will re-generate your database again.

Upvotes: 2

Related Questions