Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The "config.server" property is required and must be of type string #1230

Open
montumodi opened this issue May 7, 2021 · 10 comments
Open

The "config.server" property is required and must be of type string #1230

montumodi opened this issue May 7, 2021 · 10 comments

Comments

@montumodi
Copy link

montumodi commented May 7, 2021

I am trying to connect to ms sql using below code but I am getting error.

const sql = require("mssql");

(async () => {
  try {
    // make sure that any items are correctly URL encoded in the connection string
    await sql.connect("mssql://sa:reallyStrongPwd123@localhost/dbName");
    const result = await sql.query("select * from mytable");
    console.dir(result);
  } catch (err) {
    console.log(err);
    // ... error checks
  }
})();

Expected behaviour:

Should be able to connect

Actual behaviour:

TypeError: The "config.server" property is required and must be of type string.
    at new Connection (/Users/abc/Documents/stuff/projects/xyz/eg-xyz-feed-ingestor/node_modules/tedious/lib/connection.js:342:13)
    at /Users/abc/Documents/stuff/projects/xyz/eg-xyz-feed-ingestor/node_modules/mssql/lib/tedious/connection-pool.js:62:23
    at new Promise (<anonymous>)
    at ConnectionPool._poolCreate (/Users/abc/Documents/stuff/projects/xyz/eg-xyz-feed-ingestor/node_modules/mssql/lib/tedious/connection-pool.js:12:12)
    at ConnectionPool._connect (/Users/abc/Documents/stuff/projects/xyz/eg-xyz-feed-ingestor/node_modules/mssql/lib/base/connection-pool.js:358:10)
    at /Users/abc/Documents/stuff/projects/xyz/eg-xyz-feed-ingestor/node_modules/mssql/lib/base/connection-pool.js:330:19
    at new Promise (<anonymous>)
    at ConnectionPool.connect (/Users/abc/Documents/stuff/projects/xyz/eg-xyz-feed-ingestor/node_modules/mssql/lib/base/connection-pool.js:329:12)
    at Object.connect (/Users/abc/Documents/stuff/projects/xyz/eg-xyz-feed-ingestor/node_modules/mssql/lib/global-connection.js:59:27)
    at /Users/abc/Documents/stuff/projects/xyz/eg-xyz-feed-ingestor/src/core/run.js:6:15

Software versions

  • NodeJS: 14.6.1
  • node-mssql: V7.0.0
  • SQL Server: Microsoft SQL Server 2019 (RTM-CU10) (KB5001090) - 15.0.4123.1 (X64) Mar 22 2021 18:10:24 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Linux (Ubuntu 20.04.2 LTS)
@nicosh
Copy link

nicosh commented May 12, 2021

Can confirm, i have the same issue with v7.0.0, while with v6.2.0 it works fine.

@dhensby
Copy link
Collaborator

dhensby commented May 13, 2021

Ok - this is probably because the new connection string parser doesn't parse these uri format strings. I'll take a look and update the readme/changelog for now

@dhensby
Copy link
Collaborator

dhensby commented May 13, 2021

Oh - and to note, the library still has the old connection string parser logic in it (it's just not used) so you can use it to parse your own connection string and then give the resolved config object to the library. I plan on removing it for v8, though.

@janu75
Copy link

janu75 commented Jun 4, 2021

I am seeing the same issue. I also noticed that the aforementioned exception from tedious ("The config.server property is required...") is not caught:

From connection-pool.js:

  const tedious = new tds.Connection(cfg)

tdc.Connection() can throw, should be wrapped in a try-catch, with a call to rejectOnce() inside the catch.

@dhensby
Copy link
Collaborator

dhensby commented Jun 8, 2021

I've opened #1254 to cover @janu75's point that the errors from the new connection do cause the promise to reject.

@n0isy
Copy link

n0isy commented Jul 29, 2021

Ok - this is probably because the new connection string parser doesn't parse these uri format strings. I'll take a look and update the readme/changelog for now

Where is the documentation for the new string format of connection string? (ex. useUTC=false...)

@dhensby
Copy link
Collaborator

dhensby commented Jul 29, 2021

Where is the documentation for the new string format of connection string? (ex. useUTC=false...)

There is no new format; simply use a standard connection string for SQL server.

You can see how the connection string values are handled here: https://github.com/tediousjs/node-mssql/blob/v7.2.0/lib/base/connection-pool.js#L92-L273

@victor-ca
Copy link

in case you encounter this

instead of:
mssql://sa:reallyStrongPwd123@localhost/dbName

use
Data Source=localhost;Initial Catalog=dbName;User ID=sa;Password=reallyStrongPwd123;trustServerCertificate=true

@Jolg42
Copy link

Jolg42 commented Oct 14, 2021

Note: the types only match config as an object and not a type here https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/mssql/index.d.ts#L396-L399

@mohd-akram
Copy link

It would be nice to be able to specify connectionString as an option like in the msnodesqlv8 driver. Currently it's all or nothing when using a connection string - I want to allow a connection string to be used but force certain options (like useUTC).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants