Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 351
Taylor C. White Avatar asked May 14 '26 05:05

Taylor C. White


1 Answers

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.

like image 160
ErikEJ Avatar answered May 15 '26 20:05

ErikEJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!