Prisma SQL Server connection error in .env file

zengzsys  于 2024-01-05  发布在  SQL Server
关注(0)|答案(1)|浏览(160)

I am new in using prisma and I need to connect to my existing database in SQL Server.

schema.prisma

  1. generator client {
  2. provider = "prisma-client-js"
  3. }
  4. datasource db {
  5. provider = "sqlserver"
  6. url = "sqlserver://10.86.240.10;initial catalog=testdb;user=sa;password=Pa$$w0rd;trustServerCertificate=true;"
  7. //url = env("DATABASE_URL")
  8. }

.env

  1. DATABASE_URL="sqlserver://10.86.240.10;initial catalog=testdb;user=sa;password=Pa{%24}{%24}w0rd;trustServerCertificate=true;"

As you can see in my schema, if I put my connection string in schema.prisma everything works fine. I can query in my database but for security purposes, I need to put my connection string in .env file and after that it starts to give an error of Authentication failed for user sa .

I tried to escape my password since it has a special character, I tried these: {Pa$$word} , {Pa%24%24w0rd} and Pa{%24}{%24}w0rd but nothing works. I also tried to remove the double quote in my connection string in .env but it doesn't work too.

Did I miss something? Please help.

cuxqih21

cuxqih211#

I already got it now, the answer is here Escaping values in connection url.

It turns out that I'm doing it wrong, the proper way to escape the special character in .env file is like this: password=Pa{$}{$}w0rd or password=Pa{$$}w0rd .

You have to wrap every special characters with curly braces to make it work.

相关问题