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

Connection failure with options object vs connection string #679

Closed
robert-sjoblom opened this issue Jul 11, 2018 · 4 comments
Closed

Connection failure with options object vs connection string #679

robert-sjoblom opened this issue Jul 11, 2018 · 4 comments

Comments

@robert-sjoblom
Copy link

robert-sjoblom commented Jul 11, 2018

Similar to #578, but different error messages.

Using a config object like so:

const config = {
  user: 'username',
  password: 'password',
  server: 'server.database.windows.net',
  database: 'serverdatabase',
  options: {
    encrypt: true
  }
};

throws the following error:

[nodemon] starting `node app.js`
2018-07-11T19:48:04.611Z app listening on port 4000
(node:19648) [DEP0064] DeprecationWarning: tls.createSecurePair() is deprecated. Please use tls.TLSSocket instead.
2018-07-11T19:48:08.708Z app ConnectionError: Login failed for user 'username'.
    at Connection.tedious.once.err (C:\...\server\node_modules\mssql\lib\tedious.js:216:17)
    at Object.onceWrapper (events.js:275:13)
    at Connection.emit (events.js:182:13)
    at Connection.processLogin7Response (C:\...\server\node_modules\tedious\lib\connection.js:1292:16)
    at Connection.message (C:\...\server\node_modules\tedious\lib\connection.js:1805:14)
    at Connection.dispatchEvent (C:\...\server\node_modules\tedious\lib\connection.js:1004:38)
    at MessageIO.<anonymous> (C:\...\server\node_modules\tedious\lib\connection.js:884:18)
    at MessageIO.emit (events.js:182:13)
    at ReadablePacketStream.<anonymous> (C:\...\server\node_modules\tedious\lib\message-io.js:101:16)
    at ReadablePacketStream.emit (events.js:182:13)

While using the connection string works:
Server=tcp:serverdatabase.database.windows.net,1433;Initial Catalog=DEPRECATED;Persist Security Info=False;User ID={username};Password={password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

running on node 10.0.0

@ghost
Copy link

ghost commented Jul 13, 2018

Well based on this, you are trying to open a connection with the user "username" while you state in your connection string that it should be "your_username", you should change your config to be using "your_username"

ConnectionError: Login failed for user 'username'.

@robert-sjoblom
Copy link
Author

are you trying to be funny? I literally cannot tell.

Changed the issue because your_username === username and your_password === password, I was just lazy and copy-pasted from microsoft.

@willmorgan
Copy link
Collaborator

I did some test to compare your connection string to the object you specified:

const { resolve } = require('mssql/lib/connectionstring');
resolve("Server=tcp:serverdatabase.database.windows.net,1433;Initial Catalog=DEPRECATED;Persist Security Info=False;User ID={username};Password={password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;")

This gives you:

{ password: 'password',
  database: 'DEPRECATED',
  connectionTimeout: 30,
  requestTimeout: undefined,
  stream: false,
  options: { encrypt: true },
  port: 1433,
  user: 'username',
  server: 'serverdatabase.database.windows.net' }

The options object in the original issue is missing both port and connectionTimeout.

Would you mind to please retry with either/both those options set, and let me know how you get on?

@willmorgan willmorgan changed the title Connection fails when not using connection string Connection failure with options object vs connection string Oct 18, 2018
@willmorgan
Copy link
Collaborator

Closing - I suspect it was a duplicate of #739

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

No branches or pull requests

2 participants