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

1

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

sql-server
entity-framework
entity-framework-core
localdb
asked on Stack Overflow Oct 21, 2019 by Taylor C. White • edited Oct 24, 2019 by Taylor C. White

2 Answers

3

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.

answered on Stack Overflow Oct 27, 2019 by ErikEJ
0

Something must be different from your original setup in the way your user security is configured on your machine or the way you installed SQL Express LocalDB.

By default system administrator users of the machine have administrative access to the instance. So adding your domain account to the local Administrators group would probably give you access.

  • Run "compmgmt.msc"
  • Under Computer Management -> System Tools -> Local Users and Groups select "Groups"
  • Double Click Administrators
  • Click Add
  • Make sure your domain is in the "From this location" text box.
  • Enter your user account name
  • Click OK

The other option is to go into the security node in SSMS, right click on Logins and select "New Login..." and then add your domain user account and give it the sysadmin server role.

answered on Stack Overflow Oct 24, 2019 by Brian Pressler

User contributions licensed under CC BY-SA 3.0