P
Prisma•2mo ago
KB

MSSQL Authentication failed against database server

I was trying to connect to MSSQL server that runs on azure. Both commands npx prisma db pull and prisma studio are able to connect and pull the data but when I am trying to connect during the runtime of the application, i get PrismaClientInitializationError: Authentication failed against database server at.... I am using a simple DATABASE_URL in a .env file to connect, and here is my db.ts file
import { PrismaClient } from '@prisma/client'

let prisma: PrismaClient
declare global {
var __db: PrismaClient | undefined
}

if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient()
prisma.$connect()
} else {
if (!global.__db) {
global.__db = new PrismaClient()
global.__db.$connect()
}
prisma = global.__db
}

export { prisma }
import { PrismaClient } from '@prisma/client'

let prisma: PrismaClient
declare global {
var __db: PrismaClient | undefined
}

if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient()
prisma.$connect()
} else {
if (!global.__db) {
global.__db = new PrismaClient()
global.__db.$connect()
}
prisma = global.__db
}

export { prisma }
Yeah, I am not sure what causes the issue, but it is odd because the npx prisma db pull and prisma studio use same connection string I wonder if anyone else had a similar experience.
2 Replies
KB
KBOP•2mo ago
Ok, I did resolve it. It might be something the dev team would want to look into. The issue was in the way Prismaclient parsed that connection string. I had several special characters in my password, but i think having multiple '@' threw it off. I updated my password to remove most of the special characters and '@' and it worked fine.
Nurul
Nurul•2mo ago
Hey @KB 👋 Thank you for letting us know. Can you confirm if you were on the latest prisma version 5.21?
Want results from more Discord servers?
Add your server