使用 JavaScript 和 SQL Server 连接现有数据库
连接你的数据库
¥Connecting your database
要连接数据库,你需要将 Prisma 架构中 datasource
块的 url
字段设置为数据库 连接网址:
¥To connect your database, you need to set the url
field of the datasource
block in your Prisma schema to your database connection URL:
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}
其中 url
是 通过环境变量设置,下面的例子连接 URL 是 使用 SQL 身份验证,但是还有 设置连接 URL 格式的其他方法
¥The url
is set via an environment variable, the following example connection URL uses SQL authentication, but there are other ways to format your connection URL
DATABASE_URL="sqlserver://localhost:1433;database=mydb;user=sa;password=r@ndomP@$$w0rd;trustServerCertificate=true"
调整连接 URL 以匹配你的设置 - 请参阅 Microsoft SQL Server 连接 URL 了解更多信息。
¥Adjust the connection URL to match your setup - see Microsoft SQL Server connection URL for more information.
确保通过 SQL Server 配置管理器 启用 TCP/IP 连接以避免
No connection could be made because the target machine actively refused it. (os error 10061)
¥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)