question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot open database requested by the login. The login failed.

See original GitHub issue

Hi,

I am trying to adapt the sample BlogSample.Tests project into my own project, I copied TestSetup.cs and all but keep getting this error… any ideas what caused it?

I am certain it isn’t SQL Server Configuration issue because the BlogSample.Tests project works fine on my computer… all tests pass but when I tried to copy those into my project I will get this error…

Test method Tests.UnitSpecs.Web.Controllers.FpxControllerSpecs.get_transaction_status_should_return_one_result threw exception: 
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Cannot open database "Blog_2016-09-23-10-09-54_1d5233f6-bb51-46bb-82b4-37b6b00fddfb" requested by the login. The login failed.
Login failed for user 'PC\rosdi'.
    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)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Core.EntityClient.EntityConnection.<Open>b__2()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
 --- End of inner exception stack trace ---
    at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__3[TResult](IEnumerable`1 sequence)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Single[TSource](IQueryable`1 source, Expression`1 predicate)
   at Business.SettingsService`1.Find(String id) in C:\Projects\FPX\Business\SettingsService.cs:line 36
   at FPX.Controllers.BaseController.GetSecureSecretForSystemId(String systemId) in C:\Projects\FPX\Web\Controllers\BaseController.cs:line 65
   at FPX.Controllers.BaseController.GenerateQueryHashBySystemId(Int32 transactionId, String systemId, String buyerBankId, Double totalAmount, String transactionDesc, String returnUrl, String buyerEmail, String extraInfo1, String extraInfo2) in C:\Projects\FPX\Web\Controllers\BaseController.cs:line 30
   at Tests.UnitSpecs.Web.Controllers.FpxControllerSpecs.<get_transaction_status_should_return_one_result>d__2.MoveNext() in C:\Projects\FPX\Tests\UnitSpecs\Web\Controllers\FpxControllerSpecs.cs:line 40
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()

Here is the sql connection string generated by the code (which is TestSetup.cs that I copied from BlogSample.Tests:

Data Source=np:\\.\pipe\LOCALDB#0FCA1F41\tsql\query;Initial Catalog=Blog_2016-09-23-10-09-54_1d5233f6-bb51-46bb-82b4-37b6b00fddfb

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
martincostellocommented, Sep 23, 2016

I’m getting the same behaviour as you where it can’t open a connection to your database as the login failed. Where exactly in your code is your new empty database supposed to be being created? If I connect to the SQL LocalDB instance created by the tests the only databases present are these ones:

image

That would explain the login error, as you can’t login to a database that doesn’t exist.

In the blog sample, the database used for the tests is created automatically by EF. Is Mehdime.Entity supposed to create the database for you?

0reactions
martincostellocommented, Sep 24, 2016

Yeah, unfortunately not. This library just manages SQL LocalDB instances, which are effectively mini SQL servers. What goes in the server (databases, users etc.) is all left to the consumer.

You raise a good point though that the example’s use of EF does create some “black magic” ambiguity.

The text of the error message is SQL server’s doing though. I imagine it’s worded in such a way to stop information disclosure via probing for whether or not a database with a specific name exists in a server.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot open database "test" requested by the login. ...
Open services(I assume the windows service has been install) · Right click on the service and goto properties. · Click on "Log On"...
Read more >
Error: Cannot Open Database Requested by the Login. ...
The first cause of the error may be that the machine name of the SQL Server needs to be specified so that the...
Read more >
SQL SERVER - FIX : ERROR : Cannot open database ...
This error occurs when you have configured your application with IIS, and IIS goes to SQL Server and tries to login with credentials...
Read more >
Cannot open database "dbname" requested by login.The ...
You just need to assign a different default database. In SSMS, connect to the server, then go to the Security section, then the...
Read more >
Cannot open database "...." requested by the login. ...
1. Open up Sql Server Management Studio, connect and login (using administrative permissions) to the SQL and Instance the database is stored on....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found