【问题标题】:Unable to use tedious with Azure database无法使用繁琐的 Azure 数据库
【发布时间】:2017-02-28 22:13:43
【问题描述】:

我有一个与 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");  
    }  
});  

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

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

-> 正在创建连接对象,但是无法建立事件“.on”。
-> 在本地部署时建立连接,而在服务器上部署时,它不起作用。

【问题讨论】:

    标签: node.js azure iis tedious


    【解决方案1】:

    根据文档here,您需要提供额外的加密连接选项。

    请为config尝试以下操作:

    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 中的数据库。

    【讨论】:

      猜你喜欢
      • 2019-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 2015-11-02
      • 2011-02-11
      • 1970-01-01
      相关资源
      最近更新 更多