我正在尝试使我的用户能够 BULK INSERT / OPENROWSET() 存储在我们的 DFS/cifs 网络共享上的 CSV 文件。
我将 MS SQL Server 2016 Standard Edition 作为域帐户运行,并且该帐户可以访问所需的文件共享。因此,如果我使用 SQL 身份验证登录到 MSSQL,它就可以正常工作。
C:\Temp>sqlcmd -N -S %DB_HOSTNAME% -U %DB_USERNAME% -P %DB_PASSWORD%
1> SELECT
2> CAST(CONNECTIONPROPERTY('auth_scheme') AS nvarchar(10)) AS auth_type,
3> COUNT(*) AS NumLines
4> FROM OPENROWSET(
5> BULK '\\example.org\myshare\path\to\mydata.csv'
6> , FORMATFILE = '\\example.org\myshare\path\to\mydata.fmt'
7> ) AS f;
8> GO
auth_type NumLines
---------- -----------
SQL 73
(1 rows affected)
但是,当我使用 Kerberos/Windows 身份验证从另一台计算机连接到 MSSQL 时,我收到以下错误:
C:\Temp>sqlcmd -N -S %DB_HOSTNAME% -E
1> SELECT
2> CAST(CONNECTIONPROPERTY('auth_scheme') AS nvarchar(10)) AS auth_type,
3> COUNT(*) AS NumLines
4> FROM OPENROWSET(
5> BULK '\\example.org\myshare\path\to\mydata.csv'
6> , FORMATFILE = '\\example.org\myshare\path\to\mydata.fmt'
7> ) AS f;
8> GO
Msg 4861, Level 16, State 1, Server DBSERVER, Line 1
Cannot bulk load because the file "\\example.org\myshare\path\to\mydata.csv" could not be opened. Operating system error code 1326(The user name or password is incorrect.).
1> SELECT CAST(CONNECTIONPROPERTY('auth_scheme') AS nvarchar(10)) AS auth_type;
2> GO
auth_type
----------
KERBEROS
(1 rows affected)
通常,如果是 Kerberos 双跃点问题,我预计错误是Access is denied
. 在这种情况下,我已经设置了MSSQLSvc/dbserver.example.org
和MSSQLSvc/dbserver.example.org:1433
SPN,验证了我正在使用 Kerberos 进行连接,并为 mssql 域帐户启用了 Kerberos 约束委派到 和HOST/FILESERVER1
SPN HOST/FILESERVER2
。
知道这个错误The user name or password is incorrect.
是什么,或者我如何从 Windows 或 SQL Server 获取更多信息?
更新 #1
我试图通过使用直接指向其中一个文件服务器的 UNC 路径来排除 DFS,但得到了同样的错误:
C:\Temp>sqlcmd -N -S %DB_HOSTNAME% -E
1> SELECT
2> CAST(CONNECTIONPROPERTY('auth_scheme') AS nvarchar(10)) AS auth_type,
3> COUNT(*) AS NumLines
4> FROM OPENROWSET(
5> BULK '\\FILESERVER1.example.org\myshare\path\to\mydata.csv'
6> , FORMATFILE = '\\FILESERVER1.example.org\myshare\path\to\mydata.fmt'
7> ) AS f;
8> GO
Msg 4861, Level 16, State 1, Server DBSERVER, Line 1
Cannot bulk load because the file "\\FILESERVER1.example.org\myshare\path\to\mydata.csv" could not be opened. Operating system error code 1326(The user name or password is incorrect.).
如果我只使用文件服务器的 netbios 名称而不是 FQDN(即。\\FILESERVER1\myshare\path\to\mydata.csv
)
更新 #2
我在 SQL Server 上启用了 Keberos 事件日志记录,再次运行 OPENROWSET() 查询,然后在系统事件日志中发现以下内容:
Log Name: System
Source: Microsoft-Windows-Security-Kerberos
Date: 3/9/2023 12:47:56 PM
Event ID: 3
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer: DBSERVER.example.org
Description:
A Kerberos error message was received:
on logon session
Client Time:
Server Time: 17:47:56.0000 3/9/2023 Z
Error Code: 0xd KDC_ERR_BADOPTION
Extended Error: 0xc0000225 KLIN(0)
Client Realm:
Client Name:
Server Realm: EXAMPLE.ORG
Server Name: cifs/DOMAINCONTROLLER01.example.org
Target Name: cifs/[email protected]
Error Text:
File: onecore\ds\security\protocols\kerberos\client2\kerbtick.cxx
Line: 1292
Error Data is in record data.