Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var Connection = require('tedious').Connection;
var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;
// Create connection to database
var config = {
userName: '$DB_USERNAME', // update me
password: '$DB_PASSWORD', // update me
server: '$DB_HOST'
}
var connection = new Connection(config);
// Attempt to connect and execute queries if connection goes through
connection.on('connect', function(err) {
if (err) {
console.log(err);
} else {
console.log('Connected');
}
});
var Connection = require('tedious').Connection;
var config = {
userName: 'yourusername',
password: 'yourpassword',
server: 'yourserver.database.windows.net',
// When you connect to Azure SQL Database, you need these next options.
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");
executeStatement();
//executeStatement1();
});
var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;
function executeStatement() {
request = new Request("SELECT TOP 10 Title, FirstName, LastName from SalesLT.Customer;", function(err) {
if (err) {
console.log(err);}
});
var Connection = require('tedious').Connection;
var config = {
userName: 'yourusername',
password: 'yourpassword',
server: 'yourserver.database.windows.net',
// When you connect to Azure SQL Database, you need these next options.
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");
executeStatement();
});
var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;
function executeStatement() {
request = new Request("SELECT TOP 10 Title, FirstName, LastName from SalesLT.Customer;", function(err) {
if (err) {
console.log(err);}
});
var result = "";
if (isNaN(cfg.options.requestTimeout))
cfg.options.requestTimeout = 15000;
if (cfg.options.requestTimeout === Infinity)
cfg.options.requestTimeout = 0;
if (cfg.options.requestTimeout < 0) cfg.options.requestTimeout = 0;
if (this.config.debug) {
cfg.options.debug = {
packet: true,
token: true,
data: true,
payload: true,
};
}
const tedious = new tds.Connection(cfg);
// prevent calling resolve again on end event
let alreadyResolved = false;
function safeResolve(err) {
if (!alreadyResolved) {
alreadyResolved = true;
resolve(err);
}
}
function safeReject(err) {
if (!alreadyResolved) {
alreadyResolved = true;
reject(err);
}
function(callback) {
log.debug('Connecting to SQL server %s%s and database %s', sqlserverName, serverSuffix, sqldbName);
connection = new Connection(config);
connection.on('connect', function(err) {
var message = 'The SQL Database can %sbe connected.';
nextStep(err, message, callback);
});
},
function(callback) {
sqlConnection.prototype.tableCount = function(table, callback) {
var self = this,
conn = new Connection(self.config);
conn.on("connect", function(err) {
if (err) {
console.log(err);
callback(err, null);
} else {
var queryString = [];
/*
select SUM(rows) As Rows
from sys.partitions p
left join sys.objects o on o.object_id = p.object_id
where (p.index_id in (0,1)) and (o.is_ms_shipped = 0) and (o.type_desc = 'USER_TABLE') and (o.name = 'table')
*/
queryString.push("SELECT SUM(rows) AS Rows");
queryString.push("FROM sys.partitions p");
queryString.push("LEFT JOIN sys.objects o ON o.object_id = p.object_id");
return new Promise((resolve, reject) => {
connection = new Connection(dbConfig)
connection.on('connect', async function (error) {
if (error) {
reject(error)
}
await doBulkInsert(csvPayload, schoolLookupDisabled, schoolData)
resolve()
})
})
}
function InputMSSql (config, eventEmitter) {
this.config = config
this.eventEmitter = eventEmitter
this.started = false
this.connection = new Connection(config.connectioninfo)
if (this.config.interval < 1) {
this.config.interval = 1
}
}
_connect () {
const { server, user, password, database, encrypt = false } = this._config
const connection = new Connection({
server,
userName: user,
password,
options: {
encrypt,
database,
...driverSettings
}
})
return new Promise((resolve, reject) => {
connection.on('connect', err => {
if (err) {
reject(err)
return
}