我正在使用Windows 10,并且最近重置了PC。之后,我重新安装了Visual Studio。当我打开以前的ASP.NET MVC项目时,在“ SQL Server对象资源管理器”下找不到我的项目数据库。
运行应用程序时,出现以下异常:
SqlException:无法打开登录请求的数据库“ Vega”。登录失败。 用户“ DESKTOP-8JL51345 \ jan”的登录失败。 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,uint waitForMultipleObjectsTimeout,bool allowCreate,only boolOneCheckConnection,DbConnectionOptions userOptions,out DbConnectionInternal connection) System.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) Microsoft.EntityFrameworkCore.Storage.RelationalConnection + d__34.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable + AsyncEnumerator + d__10.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy + d__7.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable + AsyncEnumerator + d__9.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor + AsyncSelectEnumerable + AsyncSelectEnumerator + d__3.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) System.Runtime.CompilerServices.ConfiguredTaskAwaitable + ConfiguredTaskAwaiter.GetResult() System.Linq.AsyncEnumerable + SelectEnumerableAsyncIterator + d__7.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) System.Runtime.CompilerServices.ConfiguredTaskAwaitable + ConfiguredTaskAwaiter.GetResult() System.Linq.AsyncEnumerable + AsyncIterator + d__10.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 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(任务任务) System.Runtime.CompilerServices.ConfiguredTaskAwaitable + ConfiguredTaskAwaiter.GetResult() System.Linq.AsyncEnumerable + d__6.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) System.Runtime.CompilerServices.TaskAwaiter.GetResult() MakesController.cs中的vega.Controllers.MakesController + d__3.MoveNext()
这是我在appsettings.json下的连接字符串:
{
"ConnectionStrings":{
"Default": "Server=(Localdb)\\MSSQLLocalDB;Database=Vega; Integrated
Security=SSPI"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
}
}
我正在使用实体框架代码优先迁移。好像重置我的PC耗尽了我的数据库。我该如何找回它?
这是迁移文件夹:
答案 0 :(得分:0)
“重新带回”的唯一方法是重置计算机时使用的外部备份机制。
假设不存在此类备份,则您的数据不见了。最好的办法就是按照您最初创建数据库的步骤,从一个空的数据库开始。
答案 1 :(得分:0)
该连接字符串曾经使用过吗? 如果使用CodeFirst,则连接字符串也应具有以下参数: providerName =“ System.Data.SqlClient” 。
具有匹配的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")
{
}
}