0
votes

I am using Windows 10 and I recently reset my PC. After that, I re-installed Visual Studio. When I opened my previous ASP.NET MVC project, I could not find my project database under "SQL Server Object Explorer".

When I run my application, I get the following exception:

SqlException: Cannot open database "Vega" requested by the login. The login failed. Login failed for user 'DESKTOP-8JL51345\jan'. System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, uint waitForMultipleObjectsTimeout, bool allowCreate, bool onlyOneCheckConnection, DbConnectionOptions userOptions, out DbConnectionInternal connection) System.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.EntityFrameworkCore.Storage.RelationalConnection+d__34.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable+AsyncEnumerator+d__10.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy+d__7.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable+AsyncEnumerator+d__9.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+AsyncSelectEnumerable+AsyncSelectEnumerator+d__3.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult() System.Linq.AsyncEnumerable+SelectEnumerableAsyncIterator+d__7.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult() System.Linq.AsyncEnumerable+AsyncIterator+d__10.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider+ExceptionInterceptor+EnumeratorExceptionInterceptor+d__5.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult() System.Linq.AsyncEnumerable+d__6.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() vega.Controllers.MakesController+d__3.MoveNext() in MakesController.cs

Here's my connection string under appsettings.json:

{
    "ConnectionStrings":{ 
        "Default": "Server=(Localdb)\\MSSQLLocalDB;Database=Vega; Integrated 
         Security=SSPI" 
    },
    "Logging": {
        "LogLevel": {
            "Default": "Warning"
        }
    }
}

I am using Entity Framework Code First Migration. It seems like resetting my PC wiped out my database. How can I bring it back?

Here's the migration folder:

enter image description here

2
Considering you said you "reset" your PC and that you had to re-install Visual Studio this implies you did a factory reset. Guessing that you did not backup a copy of your database Vega, nor have you reinstalled SQL Server Local or restored said database. If, however, you did not backup your database (and store the copy somewhere other than your PC prior to wiping it), then it's gone now I'm afraid. You can't bring something back after a factory reset.Larnu
So, in my project, I have a folder called migrations with all the migrations. Is there a command I can execute to run all the migrations?bangbang
What do you mean "all of the migrations" we can't see what you see, so I have no idea.Larnu
I have added it in the questionbangbang

2 Answers

0
votes

The only way to "bring it back" would be an external backup mechanism you had when you reset your computer.

Assuming no such backup exists, your data is gone. The best you can do is follow the steps you took to create the database in the first place, to start over with an empty database.

0
votes

Has it ever worked with this connection string? If you use CodeFirst your connection string should have following parameter too: providerName="System.Data.SqlClient".

Example connection string with the matching DBContext-Class

<connectionStrings>
<add name="DefaultConnection" 
     connectionString="data source=(localdb)\MSSQLLocalDB; 
     initial catalog=PlutoCodeFirst; 
     integrated security=SSPI" 
     providerName="System.Data.SqlClient"/>

  public class PlutoContext : DbContext
{

    public PlutoContext() 
        : base("name=DefaultConnection")
    {

    }
}