KB
KB
PPrisma
Created by KB on 10/26/2024 in #help-and-questions
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.
4 replies