Node.js
Node.js
This page outlines the steps to connect Node.js to the CData Connect Cloud Virtual SQL Server API.
Prerequisites
Before you connect, you must first do the following:
- Connect a data source to your CData Connect Cloud account. See Connections for more information.
- Generate a Personal Access Token (PAT) on the Settings page. Copy this down, as it acts as your password during authentication.
Connecting to CData Connect Cloud
In order to connect from Node.js to CData Connect Cloud via the SQL Server interface, you need the following information:
-
Server—tds.cdata.com
-
Port—14333
-
Database name—接続したいCData Connect Cloud データソースのConnection Name を入力します。例:Salesforce1
-
Username—CData Connect Cloud のユーザー名を入力します。ユーザー名は、CData Connect Cloud の画面の右上に表示されています。例:test@cdata.co.jp
-
Password—Settings ページで生成したPAT を入力します。
Use the following code to connect to your database with Node.js, and change the following:
-
Update
user
with your CData Connect Cloud username. -
Update
password
with the PAT you generated in the prerequisites. -
Update
database
with the name of the data source you created in the prerequisites. -
Replace the
query
with your database query.
var sql = require('mssql')
var config = {
server: 'tds.cdata.com',
port: 14333,
user: 'user@mydomain.com', //your Connect Cloud username
password: 'CONNECT_USER_PAT', //your Connect Cloud PAT
options: {
encrypt: true,
database: 'SAPHANA1' //the name of your database connection
}
}
sql.connect(config, err => {
if(err){
throw err ;
}
new sql.Request().query('SELECT * FROM Buckets', (err, result) => { //your query
console.dir(result)
})
});
sql.on('error', err => {
console.log("SQL Error: " ,err);
})