node.js - 无法使用Azure数据库进行繁琐的操作

标签 node.js azure iis tedious

我有一个 Node 应用程序,它确实有到 SQL Server 的连接。
另外,我正在使用 Azure 的数据库即服务。

代码片段:

import { Connection } from 'tedious';  
import { Request } from 'tedious';  

var config = {  
    userName: 'dbuser',  
    password: 'dbpassword',  
    server: 'mydatabase.database.windows.net',  
    options: {  
        instanceName: 'SQLEXPRESS', // Removed this line while deploying it on server as it has no instance.  
        database: 'dbname'  
    }  
};  

connection = new Connection(config);  

connection.on('connect', function(err) {  
    if (err) {  
        console.log('error : '+err);  
    } else {  
        console.log("Connected to Database");  
    }  
});  

如果已在本地完成连接,则已成功连接。
控制台输出 => 连接到数据库。

使用控制台日志进行深入研究:

-> Connection object is being created, but, the event ".on" is not being able to establish.
-> The connection gets established when deployed locally, while, when deployed on server, it doesn't works.

最佳答案

基于文档here ,您需要提供一个额外的加密连接选项。

请尝试以下配置:

var config = {  
    userName: 'dbuser',  
    password: 'dbpassword',  
    server: 'mydatabase.database.windows.net',  
    options: {  
        database: 'dbname',
        encrypt: true //Need to add this for connecting to Azure DB  
    }  
};  

使用此配置,我能够连接到 Azure 中托管的数据库。

关于node.js - 无法使用Azure数据库进行繁琐的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42505548/

相关文章:

node.js - 如何在nodejs中保存返回的protobuf对象?

服务器端的 Node.js 事件与线程编程

node.js - http.get 带空格的 url

Azure 响应时间监控每个 URL 的范围

iis - IIS7 中的 DefaultAppPool 和经典 .NET AppPool 有什么区别?

javascript - 尝试在 Windows 上执行 package.json 中的脚本会引发 JScript 错误

c# - 使用 ServiceBusTrigger 的 Azure Function .Net 5

javascript - 在 TypeScript 中初始化 Azure 应用程序客户端

http - 如何访问 IIS 服务器管理器中的请求监视器?

javascript - Visual Studio 2013 IIS 网站 - JS 文件问题