如何使用Java脚本检查与Azure数据库的连接? [英] How do I check for connection to Azure Database using Javascript?

查看:90
本文介绍了如何使用Java脚本检查与Azure数据库的连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据用于Azure数据库的Cordova应用程序的文档,我将使用此代码连接到Azure数据库...

According to the documentation for the Cordova App for Azure Database, I would use this code to connect to the Azure Database...

       客户端=新的WindowsAzure.MobileServiceClient('https://strivemobileapp.azurewebsites.net');
        todoItemTable = client.getTable(tableName);

        client = new WindowsAzure.MobileServiceClient('https://strivemobileapp.azurewebsites.net');
        todoItemTable = client.getTable(tableName);

        todoItemTable.read();

        todoItemTable.read();

但是,现在我的问题是如何检查是否存在连接?有人知道这是怎么回事吗?我是否必须使用if()来检查client或todoitemtable是否为null?

However, now my problem is how do I check to see if there is a connection? Does anyone know how this works? Would I have to use an if() to check if client or todoitemtable is null?

推荐答案

Hello,

The following example shows how to check for errors trying to connect to SQL Azure:

var Connection = require('tedious').Connection; 

var config = { 

 

    userName: 'yourusername', 

 

    password: 'yourpassword', 

 

    server: 'yourserver.database.windows.net', 

    // If you are on Microsoft Azure, you need this: 

    options: {encrypt: true, database: 'AdventureWorks'} 

}; 

var connection = new Connection(config); 

connection.on('connect', function(err) { 

// If no error, then good to proceed. 

 

    console.log("Connected"); 

}); 


Hope this helps.


Regards,

SQLCoffee.com

Alberto Morillo
SQLCoffee.com


这篇关于如何使用Java脚本检查与Azure数据库的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆