tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.22k stars 464 forks source link

node-mssql only works if TCP/IP for SQL Server is turned on #1649

Closed imjosh closed 1 week ago

imjosh commented 1 month ago

node-mssql cannot connect to SQL Server unless TCP/IP is turned on.

I had to find this out from StackOverflow. I did just find an old, closed issue for this: #574

Enabling TCP/IP in the SQL Server

I think this might be unique to the tedious driver because I know that standalone msnodesqlv8 doesn't need TCP/IP, but I didn't test node-mssql with the msnodesqlv8 driver to find out.

Expected behaviour:

For the getting started code to work with SQL Server's default configuration, or for the TCP/IP requirement to be documented

Actual behaviour:

ConnectionError: Failed to connect to localhost:1433 - Could not connect (sequence) at C:\Users\Josh\Documents\GitHub\myproject\node_modules\mssql\lib\tedious\connection-pool.js:85:17 at Connection.onConnect (C:\Users\Josh\Documents\GitHub\myproject\node_modules\tedious\lib\connection.js:838:9) at Object.onceWrapper (node:events:634:26) at Connection.emit (node:events:519:28) at Connection.emit (C:\Users\Josh\Documents\GitHub\myproject\node_modules\tedious\lib\connection.js:959:18) at Connection.socketError (C:\Users\Josh\Documents\GitHub\myproject\node_modules\tedious\lib\connection.js:1340:12) at C:\Users\Josh\Documents\GitHub\myproject\node_modules\tedious\lib\connection.js:1133:14 at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {code: 'ESOCKET', originalError: Error: Failed to connect to localhost:1433…nect (sequence) at Connection.socketE…, name: 'ConnectionError', stack: 'ConnectionError: Failed to connect to localho…ons (node:internal/process/task_queues:77:11)', message: 'Failed to connect to localhost:1433 - Could not connect (sequence)'}

Configuration:

import sql from 'mssql'
(async () => {
    try {
        // make sure that any items are correctly URL encoded in the connection string
        await sql.connect('Server=myservername,1433;Database=mydbname;User Id=username;Password=password;Encrypt=false')
        const result = await sql.query`select * from mytable where id = ${value}`
        console.dir(result)
    } catch (err) {
        // ... error checks
    }
})()`

Software versions

imjosh commented 1 month ago

TCP/IP is required even when using the msnodesqlv8 driver. It gives this error:

Error during bulk insert: ConnectionError: Error: [Microsoft][SQL Server Native Client 11.0]TCP Provider: No connection could be made because the target machine actively refused it. ,Error: [Microsoft][SQL Server Native Client 11.0]Login timeout expired,Error: [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. at PrivateConnection.callback2 (c:\Users\Josh\Documents\GitHub\myproject\node_modules\mssql\lib\msnodesqlv8\connection-pool.js:46:17) at Immediate.<anonymous> (c:\Users\Josh\Documents\GitHub\myproject\node_modules\msnodesqlv8\lib\connection.js:43:14) at process.processImmediate (c:\Users\Josh\Documents\GitHub\myproject\lib\internal\timers.js:478:21) at process.callbackTrampoline (node:internal/async_hooks:130:17) {code: undefined, name: 'ConnectionError', stack: 'ConnectionError: Error: [Microsoft][SQL Serve…Trampoline (node:internal/async_hooks:130:17)', message: 'Error: [Microsoft][SQL Server Native Client …ore information see SQL Server Books Online.'}

dhensby commented 1 month ago

I'm happy to accept a clarification to the docs if you're willing to author it.

dhensby commented 1 week ago

fixed in #1651