0

I am new to SQL Server and i am trying to establish connection between Nodejs and SQL Server which is hosted on my Local Machine which is authenticated using Windows Authentication

Here is my Connection Configurations

const sql = require("mssql");
require("msnodesqlv8");
const conn = new sql.ConnectionPool({
  database: "ApplicantsData",
  server: "localhost",
  driver: "msnodesqlv8",
  options: {
    trustedConnection: true,
    TrustServerCertificate:true
  }
});
conn.connect().then(() => {
//check
});

whenever i try to connect i got an error of

Failed to connect to localhost:1433 - certificate is not yet valid

i have searched for this type of error and i ensured that:

  1. TCP/IP enabled using SQL Server Configurations
  2. Enabled SQL Server Browsing

any solutions/fixes?

Mido Ashraf
  • 99
  • 1
  • 9
  • If you are using SSPI to connect to SQL Sever, why are you providing -> TrustServerCertificate:true? – Ross Bush Jul 23 '22 at 01:39
  • @RossBush nothing in particular i saw previous answer that included TrustServerCertificate – Mido Ashraf Jul 23 '22 at 01:43
  • You don't need that if you can access the local instance when you log in. Try removing that line and see if you get a better result. – Ross Bush Jul 23 '22 at 01:45
  • I tried to remove this line but nothing changes – Mido Ashraf Jul 23 '22 at 01:57
  • Did you allow mixed mode authentication for that sql server instance? – Ross Bush Jul 23 '22 at 02:02
  • Also, check out the answer for this question as it may apply. new sql.Connection instead of ConnectionPoool. https://stackoverflow.com/questions/33709807/how-to-connect-to-sql-server-with-windows-authentication-from-node-js-using-mssq – Ross Bush Jul 23 '22 at 02:05
  • @RossBush i haven't allowed mixed mode authentication i will check it – Mido Ashraf Jul 23 '22 at 02:07
  • Unlike connection string keywords in .NET, Node/Javascript config parameters are case-sensitive. i.e.: `node --eval="console.log(JSON.stringify({FOO:1,foo:2}));"` outputs `{"FOO":1,"foo":2}`. Have you tried using `trustServerCertificate` instead of `TrustServerCertificate`? – AlwaysLearning Jul 23 '22 at 07:19
  • Also, for Windows authentication (which assumes that the Node process is executing in a Windows account context for which there is a Windows Logon configured at the SQL Server), you're probably looking for `options.trustedConnection`, ref: [Microsoft / Contributors Node V8 Driver for Node.js for SQL Server](https://www.npmjs.com/package/mssql#microsoft--contributors-node-v8-driver-for-nodejs-for-sql-server). – AlwaysLearning Jul 23 '22 at 07:23

1 Answers1

0

This is a problem with your current date and time of your IoT, where the nodejs is running(assume linux). set the date and time using below command.

date MMDDHHMMYYYY

For instance,

date 062611102023

then set the hwclock with

hwclock --systohc

Run the .js again.

Eric Wu
  • 908
  • 12
  • 35