简体   繁体   English

Node.js 使用实例名称、端口和域连接到 SQL 服务器

[英]Node.js connection to SQL Server using instance name, port, and domain

I'm building a Node.js application which is trying to connect to a very specific SQL Server configuration: It's running as an instance, with a custom port and users need to login through Active Directory-- hence the connection should be done using domain我正在构建一个 Node.js 应用程序,它试图连接到一个非常具体的 SQL 服务器配置:它作为实例运行,具有自定义端口,用户需要通过 Active Directory 登录——因此应该使用域完成连接

I'm using mssql package using tedious API, and this is my configuration:我正在使用 mssql package 使用繁琐的 API,这是我的配置:

connectionOptions = {
    server: 'USRCMX01\\INSTANCE1',
    port: 1367,
    domain: 'stagingsv',
    user: 'x.myuser.01',
    password: 'myuserpassword',
    options: {
        instanceName: 'INSTANCE1',
        trustServerCertificate: true,
        enableArithAbort: true
    }
};

However, when using this configuration I get a timeout error from SQL Server.但是,使用此配置时,我从 SQL 服务器收到超时错误。 After initiating SQL Server Browser service and opening port 1434 from my SQL Server instance server, I tried again but had the same luck在启动 SQL 服务器浏览器服务并从我的 SQL 服务器实例服务器打开端口 1434 后,我再次尝试但运气相同

The connection string I was using before from SQL Server Management studio looks like this:我之前使用的 SQL 服务器管理工作室的连接字符串如下所示:

Driver={SQL Server Native Client 11.0};Server={USRCMX01\\INSTANCE1,1367};Uid={stagingsv\\x.myuser.01};Pwd={myuserpassword};Trusted_Connection={true};

.. And it works flawlessly ..它完美无缺

Is there any way to connect to a SQL Server instance using instance name, domain, and port at the same time from Node.js?有什么方法可以同时使用实例名称、域和端口从 Node.js 连接到 SQL 服务器实例?

Windows Authentication for SQL does not use passwords. Windows SQL 的身份验证不使用密码。 It uses the credentials of the existing logged-in user.它使用现有登录用户的凭据。

So your SSMS connection string is actually ignoring the username and password, and you shouldn't pass it.所以你的 SSMS 连接字符串实际上忽略了用户名和密码,你不应该通过它。 To get the same effect with Tedious, it looks from the docs like you need to set:为了获得与 Tedious 相同的效果,从文档中看起来您需要设置:

 authentication.type = 'ntlm'

But if not then try some of the other options from there also.但如果没有,那么也可以尝试其他一些选项。

The way Windows Auth works is that it passes the Kerberos ticket (for AD users) or NTLM hash (for non-AD) that the user already has from when they logged in. There is no password in the connection string Windows Auth 的工作方式是它传递用户在登录时已经拥有的 Kerberos 票证(对于 AD 用户)或 NTLM hash(对于非 AD)。连接字符串中没有密码


Caveat : if you are using Azure AD, as opposed to on-premise, then that works differently.警告:如果您使用的是 Azure AD,而不是内部部署,则工作方式不同。 You can either use a password or the Kerberos ticket.您可以使用密码或 Kerberos 票证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM