Repository: tediousjs/node-mssql (js)

Issue:
Connection Timeout in connection string is misinterpreted as milliseconds
It seems that this library interprets the `Connection Timeout` property, when specified on the connection string, in milliseconds rather than in seconds.

[Seconds is the correct interpretation](https://www.connectionstrings.com/all-sql-server-connection-string-keywords/):

| Keyword | Default | Explanation |
| --------- | -------- | ------------ |
| Connect Timeout - or - Connection Timeout | 15 | The length of time **(in seconds)** to wait for a connection to the server before terminating the attempt and generating an error.





Not adhering to that generates all sorts of problems. For example, it's impossible to re-use a connection string with this property between a JS application with this library and a .NET application, because the .NET application will interpret the connection string correctly.

As a workaround, you can do something like this, but it's ugly and really shouldn't be necessary:
```
const transform = connectionString =>
    connectionString.replace(/Connection Timeout=(\d+)/, 'Connection Timeout=$1000')

mssql.connect(transform(connectionString))
```

### Expected behaviour:

Consider the following code (and especially the `Connection Timeout=10` at the end of the first line):
```
const connectionString = 'Server=mydbserver;Initial Catalog=mydb;Persist Security Info=False;User ID=user;Password=p4ssw0rd=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=10;'
mssql.connect(connectionString)
    .then(() => mssql.query('select * from sys.tables'))
    .then(console.log)
```
I expect that code to connect and list the information about all tables in the database.

### Actual behaviour:
Instead, the connect attempt times out after 10ms (unless you have a really fast database, in which case use a lower value to reproduce. But I doubt it...).

### Software versions

  * NodeJS: 10.11
  * node-mssql: 4.2.1
  * SQL Server: Microsoft SQL Azure (RTM) - 12.0.2000.8


Pull request:
Interpret Connection Timeout in seconds, not milliseconds
This PR implements a shift from interpreting `Connection Timeout` in milliseconds, to interpreting it in seconds, when it comes from a connection string, as an attempt to fix #741.

Since this is a breaking change, it might be nice to expose some flag that can toggle this behavior, so the old behavior is still available for users who depend on it; so far nothing in that direction has been added.

Patch:
diff --git a/lib/connectionstring.js b/lib/connectionstring.js
index e3d232b..20ba951 100644
--- a/lib/connectionstring.js
+++ b/lib/connectionstring.js
@@ -235,7 +235,7 @@ const resolveConnectionString = function (string, driver) {
     config.options.useUTC = utc === 'true' || utc === 'yes' || utc === '1'
   }
   if (config.connectionTimeout != null) {
-    config.connectionTimeout = parseInt(config.connectionTimeout, 10)
+    config.connectionTimeout = parseInt(config.connectionTimeout, 10) * 1000
   }
   if (config.requestTimeout != null) {
     config.requestTimeout = parseInt(config.requestTimeout, 10)


Test patch:
diff --git a/test/common/unit.js b/test/common/unit.js
index 751bea7..b4d3744 100644
--- a/test/common/unit.js
+++ b/test/common/unit.js
@@ -62,7 +62,7 @@ describe('Connection String', () => {
     return done()
   })
 
-  return it('Connection String #6 (multiSubnetFailover)', done => {
+  it('Connection String #6 (multiSubnetFailover)', done => {
     let cfg = cs.resolve('Server=192.168.0.1;Database=testdb;User Id=testuser;Password=testpwd;MultiSubnetFailover=True')
 
     assert.strictEqual(cfg.options.multiSubnetFailover, true)
@@ -74,6 +74,18 @@ describe('Connection String', () => {
 
     return done()
   })
+
+  return it('Connection String #7 (connection timeout)', done => {
+    let cfg = cs.resolve('Server=192.168.0.1;Database=testdb;User Id=testuser;Password=testpwd;Connection Timeout=30')
+    assert.strictEqual(cfg.user, 'testuser')
+    assert.strictEqual(cfg.password, 'testpwd')
+    assert.strictEqual(cfg.database, 'testdb')
+    assert.strictEqual(cfg.server, '192.168.0.1')
+    assert.strictEqual(cfg.port, undefined)
+    assert.strictEqual(cfg.connectionTimeout, 30000)
+
+    return done()
+  })
 })
 
 describe('Unit', () => {