简体   繁体   English

如何解决“ConnectionError:无法连接到<server> :<port> 在 15000 毫秒内”错误?

[英]How do I fix the "ConnectionError: failed to connect to <server>:<port> in 15000ms" error?

First time creating a Node/Express api to an Azure SQL Server database.第一次为 Azure SQL Server 数据库创建 Node/Express api。 It seems like this is just a matter of extending the timeout limit, but it's also just a connection to the database and not an actual query.看起来这只是延长超时限制的问题,但它也只是与数据库的连接,而不是实际查询。 Is this normal for connecting to Azure and is it actually an issue that extending the timeout will fix or is something else the problem?这对于连接到 Azure 是否正常,实际上是延长超时将解决的问题还是其他问题?

index.js索引.js

var express = require('express');
var router = express.Router();
const sql = require("../dboperation")

/* GET root route */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

// Test db connection
router.get('/testconnect', function(req, res, next) {
  sql.getdata();
  res.render('index', { title: 'Express' });
});

module.exports = router;

dboperation.js数据库操作.js

var config = require("./dbconfig")
const sql = require("mssql")


async function getdata(){
    try {
        let pool = await sql.connect(config)
        console.log("SQL Server connnected...")
    } catch(error) {
        console.log("error: " + error)
    }
}

module.exports = {
    getdata: getdata,
}

dbconfig.js数据库配置文件

const config = {
    user : "username",
    password : "password",
    server : "server-name.database.windows.net",
    database : "database-name",
    options: {
        trustedConnection: true, 
        enableArithAort: true,
        encrypt: true
    },
    port: 49678
}

module.exports = config;

SQL Server Configuration Manager: SQL Server 配置管理器:

在此处输入图片说明

在此处输入图片说明

You can try by extending timeout once.您可以尝试延长一次超时时间。

Assuming you have set the appropriate environment variables, you can construct a config object as follows:假设您已经设置了适当的环境变量,您可以按如下方式构造一个配置对象:

const sql = require('mssql')

const sqlConfig = {

  user: process.env.DB_USER,

  password: process.env.DB_PWD,

  database: process.env.DB_NAME,

  server: 'localhost',

  pool: {

    max: 10,

    min: 0,

    idleTimeoutMillis: 30000

  },

  options: {

    encrypt: true, // for azure

    trustServerCertificate: false // change to true for local dev / self-signed certs

  }

}



async () => {

 try {

  // make sure that any items are correctly URL encoded in the connection string

  await sql.connect(sqlConfig)

  const result = await sql.query`select * from mytable where id = ${value}`

  console.dir(result)

 } catch (err) {

  // ... error checks

 }

}

Reference link - https://tediousjs.github.io/node-mssql/参考链接 - https://tediousjs.github.io/node-mssql/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 [连接错误:15000 毫秒内无法连接到 IP] - [ConnectionError: Failed to connect to IP in 15000ms] ConnectionError:无法连接到localhost:15000ms内未定义 - ConnectionError: Failed to connect to localhost:undefined in 15000ms 连接到 SQL 服务器时出现超时错误:连接错误:无法在 15000 毫秒内连接到 servername\instancename - Timeout error while connecting to SQL Server: Connection Error: Failed to connect to servername\instancename in 15000ms 无法在 15000 毫秒内连接到 mydb.database.windows.net:1433(Microsoft Azure SQL 数据库) - Failed to connect to mydb.database.windows.net:1433 in 15000ms (Microsoft Azure SQL Database) 系列请求错误:SqlContext 错误。 步骤“GetData”失败:“超时:请求未能在 15000 毫秒内完成 - seriate RequestError: SqlContext Error. Failed on step “GetData” with: "Timeout: Request failed to complete in 15000ms 天蓝色的移动服务调用sql服务器存储过程并获得requestTimeout 15000ms错误 - azure mobile services calling sql server stored procedure and get a requestTimeout 15000ms error ConnectionError:无法连接到{数据库服务器}-无法连接(顺序) - ConnectionError: Failed to connect to {database server} - Could not connect (sequence) ConnectionError:无法连接到MyServer:1433 - ConnectionError: Failed to connect to MyServer:1433 ConnectionError:无法在nodeJS中的mssql中进行连接 - ConnectionError: Failed to connect in mssql in nodeJS 如何修复此错误:localhost/:1 加载资源失败:服务器响应状态为 404(未找到),无法获取 / - How do i fix this error: localhost/:1 Failed to load resource: the server responded with a status of 404 (Not Found), Cannot Get /
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM