Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQL Server Express存在Hangfire连接问题:用户登录失败_C#_Sql Server_Ssms_Sql Server Express_Hangfire - Fatal编程技术网

C# SQL Server Express存在Hangfire连接问题:用户登录失败

C# SQL Server Express存在Hangfire连接问题:用户登录失败,c#,sql-server,ssms,sql-server-express,hangfire,C#,Sql Server,Ssms,Sql Server Express,Hangfire,我正在尝试连接到我的Hangfire service中的SQL Server Express myStartup.cs中的代码如下所示: services.AddHangfire(configuration => configuration .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) .UseSimpleAssemblyNameTypeSerializer()

我正在尝试连接到我的
Hangfire service
中的SQL Server Express

myStartup.cs中的代码如下所示:

services.AddHangfire(configuration => configuration
            .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
            .UseSimpleAssemblyNameTypeSerializer()
            .UseRecommendedSerializerSettings()
            .UseSqlServerStorage(Configuration.GetConnectionString("HangfireConnection"), new SqlServerStorageOptions
            {
                CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
                SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
                QueuePollInterval = TimeSpan.Zero,
                UseRecommendedIsolationLevel = true,
                UsePageLocksOnDequeue = true,
                DisableGlobalLocks = true
            }));

        services.AddHangfireServer();
根据文档,Hangfire 1.7构建了ib sql查询来创建数据库

我使用文档中的默认连接字符串:

"HangfireConnection": "Server=.\\sqlexpress; Database=Hangfire; Integrated Security=SSPI;"
但当我运行我的应用程序时,会出现以下错误:

System.Data.SqlClient.SqlException:'无法打开登录请求的数据库“Hangfire”。登录失败。
用户“DESKTOP-FOVJ16Q\Michal”登录失败

SQL Server Express中的“我的
安全性”
选项卡如下所示:

services.AddHangfire(configuration => configuration
            .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
            .UseSimpleAssemblyNameTypeSerializer()
            .UseRecommendedSerializerSettings()
            .UseSqlServerStorage(Configuration.GetConnectionString("HangfireConnection"), new SqlServerStorageOptions
            {
                CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
                SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
                QueuePollInterval = TimeSpan.Zero,
                UseRecommendedIsolationLevel = true,
                UsePageLocksOnDequeue = true,
                DisableGlobalLocks = true
            }));

        services.AddHangfireServer();

您能告诉我,我可以通过什么检查与我的SQL Server Express建立连接

EDIT1

我的SQL Server Express“安全”选项卡,带有
登录名

My
DESKTOP-FOVJ16Q\Micha
属性:

EDIT2

我现在检查了,从该连接字符串:

"Server=.\\SQLEXPRESS;Database=TaskManager;Trusted_Connection=True;"

我只需在我的
SQL Express
中创建数据库,然后在
Management studio

中查看它,如果您阅读链接到()的页面上的评论,您会发现“Fabian Schneiter”提出了一个问题,他提出的问题与您提出的问题几乎相同-得到了以下回答:

您需要首先在服务器上创建数据库
Hangfire
。。我知道,hangfire也会创建DB,但这是错误的。如果您有一个Hangfire数据库,Hangfire将创建所有需要的表


因此,我的建议是:尝试创建
Hangfire
数据库作为一个新数据库-然后再次运行代码,看看它是否有效检查两件事:(1)SQL Server Express实例中是否有此Windows用户
DESKTOP-FOVJ16Q\Michal
的登录名?(2)在您的
Hangfire
数据库中是否有一个用户引用了该登录名?@marc_s看看我的编辑,我向您展示了我的
桌面
用户凭据
Hangfire
数据库甚至没有创建,因为sql Express的
登录失败
给桌面-FOVJ16Q\Michal
系统管理员
权限,并授予连接到sql的权限,您应该设置。(注意,有时您需要以管理员身份运行应用程序(或visualstudio)。@marc_s基于
Hangfire
文档,最新版本的数据库是自己创建的:。@iSR5我为
desktop
用户提供所有权限。比亚迪默认它是
sysadmin
Grant
连接,我做一个简单的查询:
创建数据库Hangfire
并编译项目。谢谢