Skip to content

Instantly share code, notes, and snippets.

@maka-io
Created November 6, 2017 14:13
Show Gist options
  • Save maka-io/dd7d4915f13c533b2a002adf91a683c3 to your computer and use it in GitHub Desktop.
Save maka-io/dd7d4915f13c533b2a002adf91a683c3 to your computer and use it in GitHub Desktop.
Microsoft SQL Server connection
const msLocalConfig = {
msHost: '',
msDb: '',
msUser: '',
msPassword: '',
msPort: 1433,
msTimeoutMilli: 20000,
msMaxPoolClients: 10,
msPoolTimeoutMilli: 30000
};
export default msLocalConfig;
import sql from 'mssql';
import colors from 'colors';
import msLocalConfig from './ms-config';
const config = {
user: process.env.MSUSER || msLocalConfig.msUser,
database: process.env.MSDATABASE || msLocalConfig.msDatabase,
password: process.env.MSPASSWORD || msLocalConfig.msPassword,
server: process.env.MSHOST || msLocalConfig.msHost,
port: process.env.MSPORT || msLocalConfig.msPort,
pool: {
max: process.env.MSMAXPOOLCLIENTS || msLocalConfig.msMaxPoolClients,
idleTimeoutMillis: process.env.MSTIMEOUTMILLI || msLocalConfig.msPoolTimeoutMilli
},
options: {
trustedConnecton: true
}
};
console.log(`[+] Enabling MS SQL client pool ...`.yellow);
const msPool = new sql.ConnectionPool(config, err => {
if (err) {
console.log(`[-] ${err}`.red);
} else {
console.log(`[+] Connection to MS SQL Server established.`.green);
}
});
export { msPool };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment