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—enter the Connection Name of the CData Connect Cloud data source you want to connect to (for example, Salesforce1).
-
Username—enter your CData Connect Cloud username. This is displayed in the top-right corner of the CData Connect Cloud interface. For example, test@cdata.com.
-
Password—enter the PAT you generated on the Settings page.
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);
})