Sql 打开时基础提供程序失败
我有一个测试,我正在运行的NUnit,但它不断失败Sql 打开时基础提供程序失败,sql,asp.net-mvc,linq,nunit,sqlexception,Sql,Asp.net Mvc,Linq,Nunit,Sqlexception,我有一个测试,我正在运行的NUnit,但它不断失败 [Test] public void CheckTeamsExist() { UsersContext context = new UsersContext(); var count = context.Events.Count(); Assert.AreSame(true, count > 10); } 我得到的确切错误信息是 QUBBasketba
[Test]
public void CheckTeamsExist()
{
UsersContext context = new UsersContext();
var count = context.Events.Count();
Assert.AreSame(true, count > 10);
}
我得到的确切错误信息是
QUBBasketballMVC.Tests.Controllers.TeamContextTest.CheckTeamsExist:
System.Data.EntityException:基础提供程序在打开时失败。
---->System.Data.SqlClient.SqlException:尝试为文件C:\Users\connor\Desktop\Desmation\u project(ASSEMBLA)\Branchs\Missional\u demo\Qub\u Website\QUBBasketballMVC附加自动命名数据库失败。测试\bin\Debug\Qub\u db.mdf。存在同名数据库,或无法打开指定的文件,或该文件位于UNC共享上。
System.Data.EntityException was unhandled by user code
HResult=-2146233087
Message=The underlying provider failed on Open.
Source=System.Data.Entity
StackTrace:
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
at System.Data.EntityClient.EntityConnection.Open()
at System.Data.Objects.ObjectContext.EnsureConnection()
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable`1 sequence)
at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
at QUBBasketballMVC.Tests.Controllers.AccountControllerTest.ExampleForMockingAccountMembershipServiceNEW() in c:\Users\connor\Desktop\dissertation_project (ASSEMBLA)\branches\interim_demo\Qub_Website\QUBBasketballMVC.Tests\Controllers\AccountControllerTest.cs:line 109
InnerException: System.Data.SqlClient.SqlException
HResult=-2146232060
Message=An attempt to attach an auto-named database for file C:\Users\connor\Desktop\dissertation_project (ASSEMBLA)\branches\interim_demo\Qub_Website\QUBBasketballMVC.Tests\bin\Debug\qub_db.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=14
LineNumber=65536
Number=15350
Procedure=""
Server=(LocalDB)\v11.0
State=1
StackTrace:
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions)
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& connection)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
InnerException:
用户代码未处理System.Data.EntityException
HResult=-2146233087
Message=基础提供程序在打开时失败。
Source=System.Data.Entity
堆栈跟踪:
位于System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(布尔openCondition、DbConnection StoreConnectionOpen、DbConnection originalConnection、字符串例外代码、字符串尝试操作、布尔和CloseStoreConnectionUnfailure)
位于System.Data.EntityClient.EntityConnection.Open()处
在System.Data.Objects.ObjectContext.EnsureReconnection()中
位于System.Data.Objects.ObjectQuery`1.GetResults(可为null`1 forMergeOption)
位于System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator()
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
在System.Data.Objects.Elink.ObjectQueryProvider.b__3[TResult](IEnumerable`1序列)
在System.Data.Objects.Elink.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1查询,表达式queryRoot)
位于System.Data.Objects.Elink.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](表达式)
在System.Linq.Queryable.Count[TSource](IQueryable`1源)处
在QUBBasketballMVC.Tests.Controllers.AccountControllerTest.ExampleForMockingAccountMembershipServiceNEW()中的c:\Users\connor\Desktop\Desmessment\U project(AssemblyA)\Branchs\Missional\demo\Qub\U Website\QUBBasketballMVC.Tests\Controllers\AccountControllerTest.cs:第109行
InnerException:System.Data.SqlClient.SqlException
HResult=-2146232060
Message=尝试为文件C:\Users\connor\Desktop\deposition\u project(assemblia)\branchs\middial\u demo\Qub\u Website\qubasketballmvc附加自动命名数据库。测试\bin\Debug\Qub\u db.mdf失败。存在同名数据库,或无法打开指定的文件,或该文件位于UNC共享上。
Source=.Net SqlClient数据提供程序
错误代码=-2146232060
等级=14
行号=65536
数字=15350
Procedure=“”
服务器=(本地数据库)\v11.0
状态=1
堆栈跟踪:
位于System.Data.SqlClient.SqlInternalConnection.OneError(SqlException异常,布尔断开连接,操作'1 wrapCloseInAction)
位于System.Data.SqlClient.TdsParser.ThroweException和Warning(TdsParserStateObject StateObjectStateObj、布尔调用方连接锁、布尔异步关闭)
位于System.Data.SqlClient.TdsParser.TryRun(RunBehavior RunBehavior、SqlCommand cmdHandler、SqlDataReader dataStream、BulkCopySimpleResultSet bulkCopyHandler、TdsParserStateObject stateObj、Boolean和dataReady)
在System.Data.SqlClient.TdsParser.Run(RunBehavior RunBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)
位于System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(布尔值登记OK)
位于System.Data.SqlClient.SqlInternalConnectionDS.AttemptOneLogin(ServerInfo ServerInfo、String newPassword、SecureString newSecurePassword、Boolean IgnoresInOpenTimeout、TimeoutTimer timeout、Boolean withFailover)
位于System.Data.SqlClient.SqlInternalConnectionDS.LoginOfAliver(ServerInfo服务器信息、字符串newPassword、SecureString newSecurePassword、布尔重定向EducserInstance、SqlConnectionString连接选项、SqlCredential凭证、超时超时)
位于System.Data.SqlClient.SqlInternalConnectionDS.OpenLoginList(超时计时器超时、SqlConnectionString连接选项、SqlCredential凭证、字符串新密码、SecureString NewSecureUserPassword、布尔重定向EduceInstance)
位于System.Data.SqlClient.SqlInternalConnectionDS..ctor(DbConnectionPoolIdentity、SqlConnectionString connectionOptions、SqlCredential凭据、对象providerInfo、String newPassword、SecureString newSecurePassword、Boolean redirectedUserInstance、SqlConnectionString userConnectionOptions)
位于System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions、DbConnectionPoolKey、Object poolGroupProviderInfo、DbConnectionPool、DBConnectionOwningConnection、DbConnectionOptions用户选项)
位于System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool池、DbConnectionOptions选项、DbConnectionPoolKey池键、DbConnectionOptions用户选项)
位于System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions用户选项)
位于System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions)
位于System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject、UInt32 waitForMultipleObjectsTimeout、Boolean allowCreate、Boolean OnlyOnEckConnection、DbConnectionOptions userOptions、DbConnectionInternal和connection)
位于System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject、TaskCompletionSource`1重试、DbConnectionOptions用户选项、DbConnectionInternal和connection)
位于System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnec
<connectionStrings>
<add name="qub_dbEntities1" connectionString="metadata=res://*/Models.entityDataModel.csdl|res://*/Models.entityDataModel.ssdl|res://*/Models.entityDataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\qub_db.mdf;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>