sails-sqlserver windows authentication - sails.js

I have built a sails web app and i am trying to connect to a remote sql server. It is not on azure.
can you use the sails-sqlserver adapter to connect to a sql server with windows authentication?
This is what i currently have in my connection.js file.
someSqlServer: {
adapter: 'sails-sqlserver',
host: 'ip address',
user: 'username',
password: 'pass',
database: 'DB', //optional
options: {
encrypt: false
}
},
I am getting a Login Failed for user: '' error. That means i am reaching something right?
thanks,
Logan

I got it to work with this:
someSqlServer: {
adapter: 'sails-sqlserver',
host: 'host',
user: 'user',
password: 'password',
database: 'db', //optional
domain: 'domain',
options: {
encrypt: false
}
},
I was trying to include the domain with the user name instead of putting it in its own field. This worked locally( localhost) and to server.

Related

Heroku Postgres - The server does not support SSL connections

I have been working on an small app and connecting with Heroku PostgreSQL, for many days was working right but now is showing me this SSL error
The server does not support SSL connections
I have been looking for solutions but I cannot find anything that works for me, my code is:
import pg from 'pg'
import db from '../config.js'
const pool = new pg.Pool({
host: db.host,
database: db.database,
user: db.user,
port: db.port,
password: db.password,
ssl: { rejectUnauthorized: false },
})
export default function query(text, params) {
return pool.query(text, params)
}
Try changing it from Pool to Client and then using that to connect and query.
async function get(){
const client = new pg.Client({
ssl: {
rejectUnauthorized: false
},
user: ...,
password: ...,
port: ...,
host: ...,
database: ...
});
client.connect();
const response = await client.query(`SELECT * FROM ...;`)
return response.rows
}
Double check your values in the Heroku database.
Also, in production, you should just need
const client = new pg.Client({
connectionString: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
},
}
The first set of code is for local connection to your db.
One last note, I would put your user, password, etc... into a .env file and don't commit that to your repo.
UPDATE:
You can also put this into a config file like ./db.config.js as the following
const pg = require('pg')
module.exports =
process.env.DATABASE_URL
?
new pg.Client({
connectionString: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
},
})
:
new pg.Client({
// connectionString: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
},
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
port: process.env.DATABASE_PORT,
host: process.env.DATABASE_HOST,
database: process.env.DATABASE
})
So if it is in production, it will use the database url, and if there is none (which is local) then it will use the username password connection.

TypeORM in NestJS can not connect to MongoDB

I install the mongodb software on my own Ubuntu server and I get the mongo string just like this mongodb://xxx:pass#42.212.159.109:27017,when I type this string in my local terminal and use mongosh mongodb://xxx:pass#42.212.159.109:27017, it works fine and the connection is success. But when I use this mongodb string in my nestjs project, when I run npm run start, the terminal output MongoServerError: Authentication failed.
app.module.ts
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => {
const username = configService.get('MONGO_USER');
const password = configService.get('MONGO_PASS');
const database = configService.get('MONGO_DATABASE');
const host = configService.get('MONGO_HOST');
const port = configService.get('MONGO_PORT');
return {
type: 'mongodb',
host,
port,
username,
password,
database,
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true,
};
},
The mongodb version is 4.1.3, TypeOrm version is 0.2.38.
Does anyone know what is the problem and how to solve it? Thank u.
I have figure out what the problem is, as the authSource of my mongodb is not the same one with the database to save data. So I should set the authSource option to admin, then it works.
return {
type: 'mongodb',
host,
port,
username,
password,
database,
authSource: 'admin',
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true,
};
Maybe you should try to use the Database URL connection string instead of host, port, username, password, ...
So instead of using this
return {
type: 'mongodb',
host,
port,
username,
password,
database,
entities: ...
...
}
you should use this
return {
type: "mongodb",
url: configService.get("DATABASE_URL"),
entities: ...
...
}

Can't solve an error "āœ– Database connection failed! Check your typeORM config file. "

Iā€™m trying to connect to RDS and seed data.
ormconfig.js
const entities = process.env.NODE_ENV === 'test' ? ['./src/**/**/*.ts'] : ['./dist/**/**/*.js'];
const logging = process.env.NODE_ENV !== 'test';
module.exports = {
type: 'postgres',
host: 'rds.ap-northeast-1.rds.amazonaws.com',
port: 5432,
username: 'postgres',
password: 'password',
database: 'db',
synchronize: true,
migrationsRun: false,
logging,
migrations: [`${__dirname}/dist/migration/*.js`],
entities,
};
// # sourceMappingURL=ormconfig.js.map
Error
āœ– Database connection failed! Check your typeORM config file.
RDS is running for sure and all the values of DB are from AWS Secrets Manager, so they are correct.
Why is this happening?

Typeorm Postgres ConnectionPool opening and closing for each request when using ssl

I am trying to establish a fixed connection pool using the typeorm for postgres in my rest service.
let option = {
name: 'default',
type: 'postgres',
host: 'host',
port: port,
username: 'username',
password: 'password',
database: 'database',
synchronize: true,
dropSchema: false,
logging: true,
ssl: {
ca: process.env.SSL_CERT,
},
entities: ['src/**/*.entity.ts'],
}
In app.ts
await createConnection(option).then(() => {
logger.debug('Database connection established');
}).catch((error: any) => {
logger.error('Database connection failed', error);
throw new Error(error);
});
When the app gets initialised the connectionpool gets established via ssl but it then closes, every time a query is executed the connection is created and then closed.
But without the ssl the connectionpool does not close until the .close method is called.
It would be helpful if someone could let me know on how to prevent the connectionpool from closing.
Or is there an option to set the time to live in ssl connection for postgres but I couldn't find reference for that in typeorm documentation.

Sails database configuration issue with postgresql

I upgrade sails to 1.0, I resolved all the other errors but not able to resolved database connection issue,
It will be really helpful if anyone can reply on this.
module.exports.datastores = {
localDiskDb: {
adapter: 'sails-disk'
},
postgreSql: {
adapter: 'sails-postgresql',
// url: 'postgresql://admin:root#localhost:5432/testdb',
// ssl: true,
host: 'localhost',
user: 'admin',
password: 'root',
database: 'testdb'
},
};
Important Error Logs
I was using password which contains %
after changing the password sails successfully connected to postgresql.
It mostly looks like bug with Sails v1 or Sails-pgsql adapter.