Skip to main content

Connect your database

To connect your database, you need to set the url field of the datasource block in your Prisma schema to your database connection URL:

prisma/schema.prisma
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}

In this case, the url is set via an environment variable which is defined in .env:

The following example connection URL uses SQL authentication, but there are other ways to format your connection URL

.env
  DATABASE_URL="sqlserver://localhost:1433;database=mydb;user=sa;password=r@ndomP@$$w0rd;trustServerCertificate=true"
info

We recommend adding .env to your .gitignore file to prevent committing your environment variables.

Adjust the connection URL to match your setup - see Microsoft SQL Server connection URL for more information.

Make sure TCP/IP connections are enabled via SQL Server Configuration Manager to avoid No connection could be made because the target machine actively refused it. (os error 10061)