我有一些旧代码,几年前(根据我的存储库提交,所有测试成功)已经不再有效了。我怀疑将我的Windows登录更改为与Microsoft Live关联的电子邮件地址可能已经引入了问题,但我不知道该怎么做才能修复它。顺便说一下,我可以使用SQL Server Management Studio来使用两个连接字符串来登录。
我使用Entity Framework根据app.config
中的连接字符串创建上下文。 " touch"命令应该创建数据库。但是,这会导致Windows和SQL Server身份验证的错误。这是Windows身份验证的代码:
var context = new CherrySqlDbContext("WindowsAuth");
var touch = context.Users.Count();
连接字符串:
Data Source=localhost;Initial Catalog=TestDB;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False
堆栈追踪:
System.Data.Entity.Core.EntityException未被用户代码
处理 的HResult = -2146233087
消息=基础提供程序在打开时失败 来源=的EntityFramework
堆栈跟踪:at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
在System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction [T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
1.<> c__DisplayClass7.b__5()
at System.Data.Entity.Core.Objects.ObjectQuery
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute [TResult](Func1 operation)
1.GetResults(Nullable
at System.Data.Entity.Core.Objects.ObjectQuery1 forMergeOption)
1..GetEnumerator> b__0()
at System.Data.Entity.Core.Objects.ObjectQuery
在System.Data.Entity.Internal.LazyEnumerator1.MoveNext()
1来源)
at System.Linq.Enumerable.Single[TSource](IEnumerable
在System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.b__3 [TResult](IEnumerable1 sequence)
1查询,表达式queryRoot)
at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable
在System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute [TResult](表达式) at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute [TResult](表达式表达式) 在System.Linq.Queryable.Count [TSource](IQueryable`1 source) at cherry.Tests.Integration.TransactionTest.RollbackShouldSucceed()在D:\ 2015 \ cherry \ cherry.Tests.Integration \ TransactionTests.cs:第74行的InnerException:
类= 11
错误码= -2146232060
的HResult = -2146232060
LineNumber上= 65536
Message =无法打开数据库" TestDB"登录请求。登录失败。
用户登录失败' MicrosoftAccount \ fubar@example.com'。
数= 4060
过程=""
服务器=本地主机
Source = .Net SqlClient数据提供者
国家= 1个
堆栈跟踪:at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal& connection) 在System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1重试,DbConnectionOptions userOptions) 在System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
1重试) 在System.Data.SqlClient.SqlConnection.Open() 在System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b__36(DbConnection t,DbConnectionInterceptionContext c) 在System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action
2操作,TInterceptionContext interceptionContext,Action3 executing, Action
3执行) 在System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection连接,DbInterceptionContext interceptionContext) 在System.Data.Entity.Core.EntityClient.EntityConnection.b__2() 在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy。<> c__DisplayClass1.b__0() 在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute [TResult](Func`1操作) 在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action操作) 在System.Data.Entity.Core.EntityClient.EntityConnection.Open() InnerException:
测试SQL Server身份验证的代码
var context = new CherrySqlDbContext("UserAuth");
var touch = context.Users.Count();
连接字符串:
Data Source=localhost;Initial Catalog=TestDB;Integrated Security=False;User ID=sa;Password=myPassword;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False
堆栈追踪:
System.Data.Entity.Core.EntityException未被用户代码
处理 的HResult = -2146233087
消息=引发了一个异常,可能是由于瞬态故障引起的。如果要连接到SQL Azure数据库,请考虑使用SqlAzureExecutionStrategy 来源= EntityFramework.SqlServer
堆栈跟踪:at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute [TResult](Func
1 operation) at System.Data.Entity.Core.Objects.ObjectQuery
1.GetResults(Nullable1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery
1..GetEnumerator> b__0() 在System.Data.Entity.Internal.LazyEnumerator1.MoveNext() at System.Linq.Enumerable.Single[TSource](IEnumerable
1来源) 在System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.b__3 [TResult](IEnumerable1 sequence) at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable
1查询,表达式queryRoot) at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute [TResult](表达式表达式) at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute [TResult](表达式表达式) 在System.Linq.Queryable.Count [TSource](IQueryable`1 source) at cherry.Tests.Integration.TransactionTest.RollbackShouldSucceed()在D:\ 2015 \ cherry \ cherry.Tests.Integration \ TransactionTests.cs:第74行的InnerException:
的HResult = -2146233087
消息=基础提供程序在打开时失败 来源=的EntityFramework
堆栈跟踪:at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
在System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions) 在System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction [T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery
1.<> c__DisplayClass7.b__5() 在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute [TResult](Func1 operation) InnerException: HResult=-2146233087 Message=An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy. Source=EntityFramework.SqlServer StackTrace: at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func
1操作) 在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action操作) 在System.Data.Entity.Core.EntityClient.EntityConnection.Open() 的InnerException: 类= 20 错误码= -2146232060 的HResult = -2146232060 LineNumber上= 0 Message =已与服务器成功建立连接,但在登录过程中发生错误。 (提供者:共享内存提供者,错误:0 - 管道的另一端没有进程。) 数= 233 服务器=本地主机 Source = .Net SqlClient数据提供程序 状态= 0 堆栈跟踪: 在System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal& connection) 在System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1重试,DbConnectionOptions userOptions) 在System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
1重试) 在System.Data.SqlClient.SqlConnection.Open() 在System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b__36(DbConnection t,DbConnectionInterceptionContext c) 在System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action
2操作,TInterceptionContext interceptionContext,Action3 executing, Action
3执行) 在System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection连接,DbInterceptionContext interceptionContext) 在System.Data.Entity.Core.EntityClient.EntityConnection.b__2() 在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy。<> c__DisplayClass1.b__0() 在System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute [TResult](Func`1操作) 的InnerException: 错误码= -2147467259 的HResult = -2147467259 消息=管道的另一端没有进程 NativeErrorCode = 233 InnerException: