-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
msnodesqlv8 implementation using TypeOrm #260
Comments
Hello thanks for taking interest in this library. I will try and checkout TypeORM and get an example working. I will report back shortly I have no experience with this library we do already support sequelize natively. |
Is this related |
Is this another query from you |
not helpful solution mentioned |
I posted this query |
They have not provided a working solution so not helpful |
I can make some progress I do not think we can choose msnodesqlv8 from config if I use as below but change node_modules\msssql\index.js but it does connect to database with trusted login. I would suggest proving the driver works OK as this is a smple change to begin development. // this needs to be further inestigated
module.exports = require('./lib/msnodesqlv8') import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from '@nestjs/config'
import { TypeOrmModule } from '@nestjs/typeorm'
@Module({
'imports': [
ConfigModule.forRoot(),
TypeOrmModule.forRoot({
type: 'mssql',
extra: {
server: 'localhost',
connectionString: 'Driver={ODBC Driver 18 for SQL Server}; Server=DESKTOP-VIUCH;UID=linux; PWD=x; Database=node;TrustServerCertificate=yes;',
}
})],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {} [21:27:47] Starting compilation in watch mode...
[21:27:52] Found 0 errors. Watching for file changes.
[Nest] 15212 - 31/08/2022, 21:27:55 LOG [NestFactory] Starting Nest application...
[Nest] 15212 - 31/08/2022, 21:27:55 LOG [InstanceLoader] TypeOrmModule dependencies initialized +208ms
[Nest] 15212 - 31/08/2022, 21:27:55 LOG [InstanceLoader] ConfigHostModule dependencies initialized +1ms
[Nest] 15212 - 31/08/2022, 21:27:55 LOG [InstanceLoader] AppModule dependencies initialized +0ms
[Nest] 15212 - 31/08/2022, 21:27:55 LOG [InstanceLoader] ConfigModule dependencies initialized +1ms
[Nest] 15212 - 31/08/2022, 21:27:55 LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +270ms
[Nest] 15212 - 31/08/2022, 21:27:55 LOG [RoutesResolver] AppController {/}: +15ms
[Nest] 15212 - 31/08/2022, 21:27:55 LOG [RouterExplorer] Mapped {/, GET} route +3ms
[Nest] 15212 - 31/08/2022, 21:27:55 LOG [NestApplication] Nest application successfully started +4ms |
use string such as Driver={ODBC Driver 17 for SQL Server};Server=(localdb)\node;Database=scratch;Trusted_Connection=yes; |
if you do not have v17 installed it can be downloaded from MS or try "Driver={SQL Server Native Client 11.0}; Server=(localdb)\node;Database=scratch;Trusted_Connection=yes; |
this seems to work import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigModule } from '@nestjs/config'
import { TypeOrmModule } from '@nestjs/typeorm'
@Module({
'imports': [
ConfigModule.forRoot(),
TypeOrmModule.forRoot({
type: 'mssql',
driver:require('mssql/msnodesqlv8'),
extra: {
driver: 'msnodesqlv8',
server: 'localhost',
connectionString: 'Driver={ODBC Driver 18 for SQL Server}; Server=DESKTOP-VIUCH90;UID=linux; PWD=x; Database=node;TrustServerCertificate=yes;',
}
})],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {} |
I really appreciate your response on my queries I tried to implement above solution as per my configuration as it's window authentication required using sql-server so no uid/pwd needs to be passed import { Module } from '@nestjs/common';
here are couple of issues
Please let me know is this the cause? or maybe the version you are using which supports driver key.
I am getting error In case if you have done any other configuration that I might have missed or is missing from below list then please advice
|
can you checkout https://github.com/TimelordUK/nest-torm-msnodesqlv8 I have checked in debugger it is arriving in msnodesqkv8 connection you are probably not even going into msnodesqlv8 [21:31:57] Starting compilation in watch mode...
[21:32:01] Found 0 errors. Watching for file changes.
[Nest] 24356 - 01/09/2022, 21:32:04 LOG [NestFactory] Starting Nest application...
[Nest] 24356 - 01/09/2022, 21:32:04 LOG [InstanceLoader] TypeOrmModule dependencies initialized +74ms
[Nest] 24356 - 01/09/2022, 21:32:04 LOG [InstanceLoader] ConfigHostModule dependencies initialized +1ms
[Nest] 24356 - 01/09/2022, 21:32:04 LOG [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 24356 - 01/09/2022, 21:32:04 LOG [InstanceLoader] ConfigModule dependencies initialized +1ms
[Nest] 24356 - 01/09/2022, 21:32:05 LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +353ms
[Nest] 24356 - 01/09/2022, 21:32:05 LOG [RoutesResolver] AppController {/}: +15ms
[Nest] 24356 - 01/09/2022, 21:32:05 LOG [RouterExplorer] Mapped {/, GET} route +3ms
[Nest] 24356 - 01/09/2022, 21:32:05 LOG [NestApplication] Nest application successfully started +5ms |
Thank you for creating this repo |
this is wrong connectionString: 'Driver={SQL Server Native Client 11.0};Server=W70100\SQLEXPRESS01;Database=Test;TrustServerCertificate=yes;', not TrustServerCertificate=yes you need Trusted_Connection=yes 'Driver={SQL Server Native Client 11.0}; Server=W70100\SQLEXPRESS01;Database=Test;Trusted_Connection=yes;' SQL Server Native Client 11.0 is a v old driver - ideally I would use a later version but msnodesqlv8 should work fine with it |
This the updated code now - @module({ }) I am getting error this error while SQL Server Browser is running Can you help me to debug what might be causing these issue's. Not sure in case any config is missing - here is the config of my window machine - |
W70100\SQLEXPRESS01 The server name actually looks wrong. This should be name of server you would ping i,e, the host name. W70100 why don’t you put a breakpoint in a debugger as I have done in my example above and connect using just mssql library which you say works. Look to see what the connection string is handed to msnodesqlv8 I do not think i can help much further as these issues have nothing to do with msnodesqlv8 as a library. connectionString: 'Driver={SQL Server Native Client 11.0};Server=W70100;Database=Test;Trusted_Connection=yes;', |
Did you handle any other config like I mentioned here #260 (comment) maybe I am missing |
I have to implement Window Authentication in Nestjs + mssql which uses TypeOrm so after lots of findings msnodesqlv8 driver was the most recommended but I don't find enough information to do so from the documentation so please advice
Issue I am facing
I found this snippet posted by people but it was not working
@module({
imports: [
ConfigModule.forRoot(),
TypeOrmModule.forRoot({
type: 'mssql',
port: Number.parseInt(process.env.DB_PORT),
database: process.env.DB_NAME,
extra: {
trustedConnection: true,
driver: require('mssql/msnodesqlv8'),
server: 'W70100\SQLEXPRESS01',
options: {
trustedConnection: true,
}
},
})
})
I get this error - ConnectionError: Login failed for user ' '.
Possibly, if someone can correct this snippet or guide why this error might be coming
Although, below snippet works fine and I can get the result from DB using Window Auth
const mypool = {
driver: 'msnodesqlv8',
server: 'W70100\SQLEXPRESS01',
database: 'Test',
port: 1433,
options: {
trustedConnection: true,
useUTC: true
},
};
const conn = new mssql.ConnectionPool(mypool).connect().then(pool => {
var request = new mssql.Request(mypool);
request.query('select * from [Test].[tin].[Emp]', (err, result) => {
if (err) console.log('Database Connection Failed! ON RESULT: ',err);
console.log(result)
})
return pool;
}).catch(err => console.log('Database Connection Failed! Bad Config: ', err))
Additional Context
I have also made sure following points are taken care -
Software/Package versions
so, please if you can correct or provide the right snippet or even example or guidance also helps
The text was updated successfully, but these errors were encountered: