Skip to content
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

Database connection error when using Prisma with Vite and SQL Server (PrismaClientInitializationError) #9971

Open
JAllanMora opened this issue Sep 10, 2024 · 0 comments

Comments

@JAllanMora
Copy link

Reproduction

1.-I migrated my project to Vite.

2.-Configuré Prisma para usar un datasource con SQL Server.

generator client {
    provider = "prisma-client-js"
}

datasource db {
    provider = "sqlserver"
    url = env("DATABASE_URL")
}

3.- My .env file includes the following connection URL:

DATABASE_URL="sqlserver://<host>:<port>;database=<dbname>;user=<user>;password=<password>;encrypt=true;trustServerCertificate=true" 

4.- When trying to initialize the Remix project, which initializes the Prisma client, I get the following error:

PrismaClientInitializationError: Error creating a database connection. (Authentication failed for user sa) at r (C:\Users\Allan\Documentos\Wincaja-Apps\node_modules.pnpm@prisma+client@4.16.2_prisma@4.16.2\node_modules@prisma\client\runtime\library.js:108:2574)

5.-If I remove the special characters from the password in the .env file, the connection works fine. Additionally, if I include the connection string directly in the Prisma file, the connection also functions correctly, even if the password contains special characters.

System Info

System Info:

Output of prisma -v:
Prisma version 4.16.2

vite version:
vite 5.4.3

Operating System:
Windows 11

Used Package Manager

pnpm

Expected Behavior

Prisma should correctly handle connection credentials, even if the password contains special characters, when using environment variables in a project with Vite.

Actual Behavior

I get a PrismaClientInitializationError due to authentication failure when using a password with special characters in the environment variable (DATABASE_URL). However, if I hardcode the connection string with the same password directly in the Prisma file, the connection works fine. Despite the initialization error, commands like npx prisma db pull and npx prisma studio run successfully, indicating that the issue only occurs during project initialization when Prisma attempts to use the environment variable for the connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants