Reputation: 71
Facing the error
Database Connection Failed! Bad Config: TypeError: The "config.server" property is required and must be of type string. at new Connection (D:\License Generation\node_modules\tedious\lib\connection.js:87:13) at base.Promise (D:\License Generation\node_modules\mssql\lib\tedious.js:237:23) at new Promise () at ConnectionPool._poolCreate (D:\License Generation\node_modules\mssql\lib\tedious.js:195:12) at ConnectionPool._connect (D:\License Generation\node_modules\mssql\lib\base.js:245:10) at PromiseLibrary (D:\License Generation\node_modules\mssql\lib\base.js:220:19) at new Promise () at ConnectionPool.connect (D:\License Generation\node_modules\mssql\lib\base.js:219:12) at Object. (D:\License Generation\dbConfig.js:6:2) at Module._compile (internal/modules/cjs/loader.js:689:30)
Configuration File
//Database Configuration
const dbconfiguration = {
server: 'xyz',
user: 'fdf',
password: 'safgfg',
database: 'License_Keys',
port: 1433
};
module.exports = dbconfiguration;
const sqlInstance = require('mssql');
const configFile = require('./app.config');
//connect to your database
const poolPromise = new sqlInstance.ConnectionPool(configFile.dbconfiguration)
.connect()
.then(pool => {
console.log('Connected to MSSQL')
return pool
})
.catch(err => console.log('Database Connection Failed! Bad Config: ', err))
module.exports = poolPromise;
Upvotes: 2
Views: 25519
Reputation: 196
Ran into this issue today, it was caused by a password that was a valid mssql password but had characters in it that were exiting the string before the reader in the package I was using could get to the server section of the string.
I was using different technology (Feathers and Knex), but dropping this here for anyone who comes across this issue in the future.
Upvotes: 0
Reputation: 1
Error:
const sequelize = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, { host: process.env.DB_HOST, dialect: 'mssql' });
Solution: Do not directly add host from config.env file.
const sequelize = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, { host: localhost, dialect: 'mssql' });
Upvotes: 0
Reputation: 19
Navigate to the "configuration" menu on your azure app service page and supply all the environment variables under "Application Settings". Under "General Settings", ensure that "npm run start" is included to enable your application to run smoothly.
Upvotes: 0
Reputation: 1257
Use directly required configFile
, as you are exporting a single const variable object from that file, you don't need to access it like configFile.dbconfiguration
This should work,
sqlInstance.ConnectionPool(configFile)
Note: To clear confusion, you can export DB configuration like this also,
//Database Configuration
module.exports = {
server: 'xyz',
user: 'fdf',
password: 'safgfg',
database: 'License_Keys',
port: 1433
};
Upvotes: 1