1

I am using mssql node.js library. How do I increase the timeout to connect to SQL Server? I have added connectionTimeout and requestTimeout, but it looks like it is still defaulting to 15000ms.

 const config = {
            server: obj.host,
            port: Number(obj.port),
            user: obj.username,
            password: obj.password,
            database: obj.dbname,
            options: {
                connectionTimeout: 50000,
                requestTimeout: 50000
            }
        };

        sql.connect(config, (err) => {
            if (err) {
                console.log(err);
            }
        console.log("Connected ... ");
         });
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Aaron
  • 1,345
  • 2
  • 13
  • 32
  • Unless you are doing some seriously heavy lifting from your application (which in nearly every situation this is a bad idea), you should look into optimizing your queries instead of increasing the timeout. 15 seconds is a LONG time to wait for an application to respond. – Sean Lange Apr 09 '19 at 16:03
  • It hasn't gotten to the query execution part. It is not even connecting to sql server. I am getting a connection timeout. @SeanLange – Aaron Apr 09 '19 at 16:06
  • I spoke with my dba. He asked me to increase the connection timeout until they fix the problem. @SeanLange – Aaron Apr 09 '19 at 16:07
  • Oh....well then something is probably wrong in your connection string or the connection pool is full. That is almost always an indication that a connection can't be made. – Sean Lange Apr 09 '19 at 16:07
  • I am getting this error message - `Failed to connect to ip in 15000ms`. I am trying to increase the `connectionTimeout` to 50000ms as seen in my code above, but it is still taking the default 15000. @SeanLange – Aaron Apr 09 '19 at 16:11
  • My guess is that will just delay how long it takes before you can't connect. But see here. https://stackoverflow.com/questions/3586760/how-do-i-set-a-timeout-for-client-http-connections-in-node-js – Sean Lange Apr 09 '19 at 16:12

0 Answers0