Blazor / Entity Framework Database Login Failure, Suddenly Started Appearing?

entity-framework entity-framework-core localdb sql-server

Question

There are a lot of related issues referencing similar database error messages, but typically they have to do with folks that are setting up databases in SQL server, but not entirely encapsulated under Blazor/Entity Framework.

I've been building a Blazor Web Assembly app which has three projects (Client, Model, Server). The Server project uses Entity Framework and created the database with all of the tables/records it serves up.

Connecting to the database has been working fine ever since the project was created, but after my machine recently crashed, when I rebuilt the solution and accessed the app, the server started throwing the following error:

Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot open database "WhiteGov" requested by the login. The login failed.
Login failed for user 'EPIC\twhite'.

(EPIC\twhite is my Windows login)

I can see and connect to the database in the solution's Server Explorer.

What can I do to fix whatever issue that has "suddenly"/"spontaneously" arisen. I have not changed the ConnectionString (below).

{
    "ConnectionStrings": {
        "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=WhiteGov;Trusted_Connection=True;"
    },
    "Logging": {
        "LogLevel": {
            "Default": "Information",
            "Microsoft": "Warning",
            "Microsoft.Hosting.Lifetime": "Information"
        }
    },
    "AllowedHosts": "*"
}

Here's more of the error:

at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) at Microsoft.Data.SqlClient.SqlConnection.OpenAsync(CancellationToken cancellationToken)

enter image description here

1
1
10/24/2019 8:31:47 PM

Popular Answer

What you are showing in Server Explorer is not your Localdb instance, but probably a SQL Server Express User instance connection. Connect to (localdb)\mssqllocaldb in Server Explorer, and verify that it contains a database named "WhiteGov" - if that is not the case, then you can attach the WhiteGov.mdf file and things will start working for you.

3
10/27/2019 1:57:06 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow