使用 Windows 身份验证登录到本地 SQL Server 实例 [英] Logging into local SQL Server instance with windows auth

查看:130
本文介绍了使用 Windows 身份验证登录到本地 SQL Server 实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 nodejs 和 express 的项目.我目前使用 sequelize 连接到 SQL Server 实例.这适用于使用 SQL Server 身份验证的外部 SQL Server.但是,我现在正在尝试使用 Windows 身份验证连接到本地 SQL Server 实例.

I have a nodejs and express based project. I currently use sequelize to connect to a SQL Server instance. This works fine for external SQL Servers using SQL Server authentication. However, I am now trying to connect to a local SQL Server instance using Windows auth.

这是我的连接字符串的样子:

This is what my connection string looks like:

export var sequelize = new Sequelize({
    dialect: 'mssql',
    dialectModulePath: 'sequelize-msnodesqlv8',
    dialectOptions: {
      connectionString: 'Server=localhost\MSSQLSERVER01;Database=DB-demo; Integrated Security=SSPI;'
    },
  });

然而,这是抛出错误:

未处理的拒绝 SequelizeConnectionError: [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: 无法打开到 SQL Server [53] 的连接.

Unhandled rejection SequelizeConnectionError: [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53].

在连接处.(C:\Users\George\Source\Repos\Test-Proj\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:109:16)
在emitOne (events.js:96:13)
在 Connection.emit (events.js:188:7)
在 mssql.open (C:\Users\George\Source\Repos\Test-Proj\node_modules\sequelize-msnodesqlv8\lib\connection.js:107:9)
在立即.(C:\Users\George\Source\Repos\Test-Proj\node_modules\msnodesqlv8\lib\ConnectionWrapper.js:336:11)
在 runCallback (timers.js:672:20)
在 tryOnImmediate (timers.js:645:5)
在 processImmediate [as _immediateCallback] (timers.js:617:5)

at Connection. (C:\Users\George\Source\Repos\Test-Proj\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:109:16)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at mssql.open (C:\Users\George\Source\Repos\Test-Proj\node_modules\sequelize-msnodesqlv8\lib\connection.js:107:9)
at Immediate. (C:\Users\George\Source\Repos\Test-Proj\node_modules\msnodesqlv8\lib\ConnectionWrapper.js:336:11)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)

注意:我可以通过 ssms 中的 windows auth 很好地连接到这个.见:

NB: I can connect fine to this with windows auth in ssms. see :

总结评论中讨论的内容 - SQL Server 浏览器正在运行,我的 SQL Server 实例确实具有 TCP/IP &已启用命名管道.

To summarise what's been discussed in the comments - SQL Server Browser is running, My SQL Server instance does have TCP/IP & Named Pipes enabled.

这是最近的错误日志:

2017-08-29 15:30:25.70 Server      Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64) 
    Oct 28 2016 18:17:30 
    Copyright (c) Microsoft Corporation
    Developer Edition (64-bit) on Windows 10 Pro 6.3 <X64> (Build 15063: )
2017-08-29 15:30:25.71 Server      UTC adjustment: 1:00
2017-08-29 15:30:25.71 Server      (c) Microsoft Corporation.
2017-08-29 15:30:25.71 Server      All rights reserved.
2017-08-29 15:30:25.71 Server      Server process ID is 13168.
2017-08-29 15:30:25.71 Server      System Manufacturer: 'Microsoft Corporation', System Model: 'Surface Pro 3'.
2017-08-29 15:30:25.71 Server      Authentication mode is WINDOWS-ONLY.
2017-08-29 15:30:25.71 Server      Logging SQL Server messages in file 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER01\MSSQL\Log\ERRORLOG'.
2017-08-29 15:30:25.71 Server      The service account is 'NT Service\MSSQL$MSSQLSERVER01'. This is an informational message; no user action is required.
2017-08-29 15:30:25.71 Server      Registry startup parameters: 
     -d C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER01\MSSQL\DATA\master.mdf
     -e C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER01\MSSQL\Log\ERRORLOG
     -l C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER01\MSSQL\DATA\mastlog.ldf
2017-08-29 15:30:25.72 Server      Command Line Startup Parameters:
     -s "MSSQLSERVER01"
2017-08-29 15:30:25.72 Server      SQL Server detected 1 sockets with 2 cores per socket and 4 logical processors per socket, 4 total logical processors; using 4 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2017-08-29 15:30:25.72 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2017-08-29 15:30:25.72 Server      Detected 4001 MB of RAM. This is an informational message; no user action is required.
2017-08-29 15:30:25.72 Server      Using conventional memory in the memory manager.
2017-08-29 15:30:25.85 Server      Default collation: Latin1_General_CI_AS (us_english 1033)
2017-08-29 15:30:25.91 Server      Buffer pool extension is already disabled. No action is necessary. 
2017-08-29 15:30:25.94 Server      InitializeExternalUserGroupSid failed. Implied authentication will be disabled.
2017-08-29 15:30:25.94 Server      Implied authentication manager initialization failed. Implied authentication will be disabled.
2017-08-29 15:30:25.95 Server      The maximum number of dedicated administrator connections for this instance is '1'
2017-08-29 15:30:25.95 Server      This instance of SQL Server last reported using a process ID of 4764 at 29/08/2017 15:30:18 (local) 29/08/2017 14:30:18 (UTC). This is an informational message only; no user action is required.
2017-08-29 15:30:25.96 Server      Node configuration: node 0: CPU mask: 0x000000000000000f:0 Active CPU mask: 0x000000000000000f:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2017-08-29 15:30:25.96 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
2017-08-29 15:30:25.97 Server      Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
2017-08-29 15:30:26.00 Server      Query Store settings initialized with enabled = 1, 
2017-08-29 15:30:26.00 spid5s      Starting up database 'master'.
2017-08-29 15:30:26.08 Server      CLR version v4.0.30319 loaded.
2017-08-29 15:30:26.15 spid5s      Resource governor reconfiguration succeeded.
2017-08-29 15:30:26.15 spid5s      SQL Server Audit is starting the audits. This is an informational message. No user action is required.
2017-08-29 15:30:26.15 spid5s      SQL Server Audit has started the audits. This is an informational message. No user action is required.
2017-08-29 15:30:26.20 spid5s      SQL Trace ID 1 was started by login "sa".
2017-08-29 15:30:26.20 spid5s      Server name is 'SURFACE\MSSQLSERVER01'. This is an informational message only. No user action is required.
2017-08-29 15:30:26.23 spid6s      Starting up database 'mssqlsystemresource'.
2017-08-29 15:30:26.23 spid14s     Starting up database 'msdb'.
2017-08-29 15:30:26.23 spid15s     Starting up database 'Prod-Sense'.
2017-08-29 15:30:26.24 spid6s      The resource database build version is 13.00.4001. This is an informational message only. No user action is required.
2017-08-29 15:30:26.32 Server      Common language runtime (CLR) functionality initialized using CLR version v4.0.30319 from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\.
2017-08-29 15:30:26.33 spid6s      Starting up database 'model'.
2017-08-29 15:30:26.37 spid6s      Polybase feature disabled.
2017-08-29 15:30:26.37 spid6s      Clearing tempdb database.
2017-08-29 15:30:26.58 spid10s     A self-generated certificate was successfully loaded for encryption.
2017-08-29 15:30:26.59 spid6s      Starting up database 'tempdb'.
2017-08-29 15:30:26.59 spid10s     Server is listening on [ 'any' <ipv6> 50465].
2017-08-29 15:30:26.59 spid10s     Server is listening on [ 'any' <ipv4> 50465].
2017-08-29 15:30:26.59 spid10s     Server local connection provider is ready to accept connection on [ \\.\pipe\SQLLocal\MSSQLSERVER01 ].
2017-08-29 15:30:26.59 spid10s     Server named pipe provider is ready to accept connection on [ \\.\pipe\MSSQL$MSSQLSERVER01\sql\query ].
2017-08-29 15:30:26.59 Server      Server is listening on [ ::1 <ipv6> 61076].
2017-08-29 15:30:26.59 Server      Server is listening on [ 127.0.0.1 <ipv4> 61076].
2017-08-29 15:30:26.59 Server      Dedicated admin connection support was established for listening locally on port 61076.
2017-08-29 15:30:26.60 spid10s     SQL Server is now ready for client connections. This is an informational message; no user action is required.
2017-08-29 15:30:26.60 Server      SQL Server is attempting to register a Service Principal Name (SPN) for the SQL Server service. Kerberos authentication will not be possible until a SPN is registered for the SQL Server service. This is an informational message. No user action is required.
2017-08-29 15:30:26.60 Server      The SQL Server Network Interface library could not register the Service Principal Name (SPN) [ MSSQLSvc/Surface:MSSQLSERVER01 ] for the SQL Server service. Windows return code: 0xffffffff, state: 63. Failure to register a SPN might cause integrated authentication to use NTLM instead of Kerberos. This is an informational message. Further action is only required if Kerberos authentication is required by authentication policies and if the SPN has not been manually registered.
2017-08-29 15:30:26.60 Server      The SQL Server Network Interface library could not register the Service Principal Name (SPN) [ MSSQLSvc/Surface:50465 ] for the SQL Server service. Windows return code: 0xffffffff, state: 63. Failure to register a SPN might cause integrated authentication to use NTLM instead of Kerberos. This is an informational message. Further action is only required if Kerberos authentication is required by authentication policies and if the SPN has not been manually registered.
2017-08-29 15:30:26.77 spid6s      The tempdb database has 4 data file(s).
2017-08-29 15:30:26.77 spid16s     The Service Broker endpoint is in disabled or stopped state.
2017-08-29 15:30:26.77 spid16s     The Database Mirroring endpoint is in disabled or stopped state.
2017-08-29 15:30:26.78 spid16s     Service Broker manager has started.
2017-08-29 15:30:26.78 spid5s      Recovery is complete. This is an informational message only. No user action is required.
2017-08-29 15:30:27.01 Server      Software Usage Metrics is disabled.
2017-08-29 15:31:54.18 spid51      Attempting to load library 'xpsqlbot.dll' into memory. This is an informational message only. No user action is required.
2017-08-29 15:31:54.18 spid51      Using 'xpsqlbot.dll' version '2015.130.1601' to execute extended stored procedure 'xp_qv'. This is an informational message only; no user action is required.
2017-08-29 15:31:58.99 spid53      Attempting to load library 'xpstar.dll' into memory. This is an informational message only. No user action is required.
2017-08-29 15:31:59.01 spid53      Using 'xpstar.dll' version '2015.130.1601' to execute extended stored procedure 'xp_regread'. This is an informational message only; no user action is required.

推荐答案

我在聊天中尝试了 4 次,但现在我在这里发布.

I tried for 4 times in chat but now I post it here.

您的服务器仅配置为 Windows 身份验证,它已写入错误日志.

Your server is configured for Windows Authentication only, it's written in error log.

要将其更改为混合模式,请在 SSMS 中右键单击您的服务器,转到属性"、安全"选项卡并将模式更改为混合模式,如图所示.

To change it to mixed mode right click your server in SSMS, go to Properties, Security tab and change the mode to mixed as shown in my picture.

然后重启你的服务器

这篇关于使用 Windows 身份验证登录到本地 SQL Server 实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆