无法使用繁琐的Azure数据库

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

它在本地有成功的连接。
控制台输出=>连接到数据库。

使用控制台日志完成深潜:

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

根据here的文档,您需要提供一个用于encryption连接的附加选项。

请尝试以下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 } }; 

使用这个configuration,我能够连接到Azure托pipe的数据库。