无法打开登录请求的数据库“身份”。登录失败。用户“DESKTOP\User”登录失败

金梅奥

所以当我尝试运行我的项目时,我一直收到这个错误......该项目是由我的一位小组成员发送给我的。

“无法打开登录请求的数据库“身份”。登录失败。用户登录失败“

该项目本身是一个使用 MVC 的 Web 应用程序。我们有一个包含俱乐部/球员名单的数据库。我目前要做的只是运行它以查看我的小组已完成的工作,但它不断向我显示上述错误。我在网上广泛搜索无济于事,这就是我在这里发帖寻求帮助的原因。

SQL Server 对象资源管理器

以下是:

IdentitySeedData.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;

namespace P0.Models
{
    public static class IdentitySeedData
    {
        private const string adminUser = "Admin";
        private const string adminPassword = "Secret123$";
        public static async void EnsurePopulated(IApplicationBuilder app)
        {
            UserManager<IdentityUser> userManager = app.ApplicationServices
                .GetRequiredService<UserManager<IdentityUser>>();

            IdentityUser user = await userManager.FindByNameAsync(adminUser);

            if (user == null)
            {
                user = new IdentityUser("Admin");
                await userManager.CreateAsync(user);
            }
        }
    }
}

AppIdentityContext.cs

using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;


namespace P0.Models
{
    public class AppIdentityDbContext : IdentityDbContext<IdentityUser>
    {
        public AppIdentityDbContext(DbContextOptions<AppIdentityDbContext> options)
            : base(options) { }
    }
}

程序.cs

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace P0
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseDefaultServiceProvider(options =>
                options.ValidateScopes = false)
                .Build();
    }
}

启动文件

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using P0.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;

namespace P0
{
    public class Startup
    {
        public Startup(IConfiguration configuration) =>
            Configuration = configuration;

        public IConfiguration Configuration { get; }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(
                    Configuration["Data:ConnectionStrings:SoccerClubs"]));
            services.AddDbContext<AppIdentityDbContext>(options =>
                options.UseSqlServer(
                    Configuration["Data:ConnectionStrings:AppIdentityDbContext"]));
            services.AddIdentity<IdentityUser, IdentityRole>()
                .AddEntityFrameworkStores<AppIdentityDbContext>()
                .AddDefaultTokenProviders();
            services.AddTransient<IClubRepository, EFClubRepository>();
            services.AddTransient<IPlayerRepository, EFPlayerRepository>();
            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();
            app.UseAuthentication();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
            SeedData.EnsurePopulated(app);
            IdentitySeedData.EnsurePopulated(app);
        }
    }
}

appsetting.json

{
  "Data": {
    "ConnectionStrings": {
      "SoccerClubs": "Server=(localdb)\\MSSQLLocalDB;Database=SoccerClubs;Trusted_Connection=True;MultipleActiveResultSets=true",
      "AppIdentityDbContext": "Server=(localdb)\\MSSQLLocalDB;Database=Identity;Trusted_Connection=True;MultipleActiveResultSets=true"
    }
    }
}
罗斯科

您的应用程序正在使用与 SQL Server 数据库的“可信连接”。所以它试图用计算机的当前用户登录。

您需要进入 SQL Server 对象资源管理器或 SQL Server Management Studio 并添加“DESKTOP\User”作为 SQL Server 的登录名和数据库中的用户。

以下是步骤

https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/create-a-database-user?view=sql-server-ver15#SSMSProcedure

添加用户页面的屏幕截图

https://serverfault.com/questions/366492/how-can-i-add-myself-to-my-local-sql-servers-windows-authentication

确保进入“用户映射”选项卡并勾选您要使用的数据库。如果这是开发,您可以勾选“db_owner”,以便您拥有所有权限。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法打开登录请求的数据库“ ASPState”。登录失败。用户“ xxxx”的登录失败

无法打开登录请求的数据库“dbTest”。登录失败。用户“testUser”登录失败

LocalDb-> Windows服务->无法打开登录请求的数据库“”。登录失败。用户“ NT AUTHORITY \ LOCAL SERVICE”的登录失败

{“登录名请求的无法打开数据库\“ Namespace.Model.DbContext \”。登录失败用户'Domain \\ myusername'的登录失败。”}

登录失败无法打开数据库

无法打开登录请求的数据库“ dbTest”。登录失败。Windows服务

com.microsoft.sqlserver.jdbc.SQLServerException: 无法打开登录请求的数据库 <database>。登录失败

连接到SQL数据库时出错:无法打开登录请求的数据库“ Students.mdf”。登录失败

asp.net无法打开数据库登录失败

用户的数据库登录失败

随机“无法打开用户默认数据库。登录失败。” Winforms项目中的错误

CouchDB:此数据库加载失败/无法打开任何数据库分片(以管理员身份登录)

NETCore 2.1-无法访问mssql服务器/ SqlExeption:无法打开登录请求的数据库“ DbName”。登录失败

基于令牌的数据库身份验证失败,并显示“用户'NT AUTHORITY \ ANONYMOUS LOGON'登录失败”。

无法打开数据库。安装 .NET 应用程序时创建 SQL Server 数据库时出现用户错误登录失败

POST 请求失败,无法登录

登录到通过 docker-compose 创建的 Postgres 数据库时,身份验证失败

Google登录失败,无法打开流Http请求失败,请求失败

连接数据库时登录失败

移动数据库和网站后登录失败

仅当数据库失败时才登录文件吗?

将登录页面与数据库连接失败

如何在Azure SQL数据库上调试“用户登录失败”?

数据库连接错误后,用户 'DOMAIN\ServerName$' 登录失败

无法登录-用户“用户名”登录失败

Azure:用户登录失败

用户sql登录失败

用户的sqlserverexception登录失败

无法以只读用户身份登录到SQL Azure数据库