Created
November 6, 2017 14:13
-
-
Save maka-io/dd7d4915f13c533b2a002adf91a683c3 to your computer and use it in GitHub Desktop.
Microsoft SQL Server connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const msLocalConfig = { | |
msHost: '', | |
msDb: '', | |
msUser: '', | |
msPassword: '', | |
msPort: 1433, | |
msTimeoutMilli: 20000, | |
msMaxPoolClients: 10, | |
msPoolTimeoutMilli: 30000 | |
}; | |
export default msLocalConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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