下层提供失败的开放 [英] Underlying Provider Failed on Open
问题描述
我有我从NUnit的运行测试,但它一直未能
I have a Test that i am running from NUnit but it keeps failing
[Test]
public void CheckTeamsExist()
{
UsersContext context = new UsersContext();
var count = context.Events.Count();
Assert.AreSame(true, count > 10);
}
确切的错误消息我得到是
The exact error message i am getting is
QUBBasketballMVC.Tests.Controllers.TeamContextTest.CheckTeamsExist:
System.Data.EntityException:基础提供开放式失败。
----> System.Data.SqlClient.SqlException:试图附加自动命名的数据库文件C:\\用户\\康纳\\桌面\\ dissertation_project(ASSEMBLA)\\分支机构\\ interim_demo \\ Qub_Website \\ QUBBasketballMVC.Tests \\ BIN \\调试\\ qub_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:
看不到我要去哪里错了!这code从我的主要项目正常工作
Can't see where i'm going wrong! This code works fine from my main project
<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>
我在这两个配置文件此连接字符串。
I have this connection string in both config files.
是实体框架文件DataDirectory目录/位置是不是在我的单元测试项目相同的问题?
Is the problem that DataDirectory/location of entity framework files is not the same in my unit test project?
推荐答案
要添加到Lilshieste的评论,
替换用硬codeD路径 app.confi
克测试项目的 DataDirectory目录
占位在App Data文件夹。
To add to Lilshieste's comment,
Replace the DataDirectory
place holder in the app.confi
g of the test project with a hard coded path to the App Data folder.
它还如果你的数据库文件(LDF MDF&AMP)复制的作品。
It also works if you copy the database files (mdf & ldf) to the bin/debug folder of the test project.
这篇关于下层提供失败的开放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!