I am new in using prisma and I need to connect to my existing database in SQL Server.
schema.prisma
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlserver"
url = "sqlserver://10.86.240.10;initial catalog=testdb;user=sa;password=Pa$$w0rd;trustServerCertificate=true;"
//url = env("DATABASE_URL")
}
.env
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.
1条答案
按热度按时间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
orpassword=Pa{$$}w0rd
.You have to wrap every special characters with curly braces to make it work.