Can't connect to a SQL Server database with a named instance
See original GitHub issueBug description
At work, I presented Prisma to my manager, and he liked it, so we want to use it in our next project. Sometimes we use MySQL, but for this project we are using SQL Server (probably Express).
The problem is trying to connect with a named instance (which is probably going to be a requirement for the project). At work, we have Windows 10 machines, and this example is from home with a Windows 11 machine. The same error occurs.
So I have 2 servers running:
- MSSQL Server
- SQL Express
Some picture of my setup:
TCP/IP is enabled for both.
Here I tried connecting using the ‘sqlcmd’ and it works for both connections.
Here are connection strings I have tried and they didn’t work:
// also for every string I also tried using \\ instead of just \ inbetween the HOST and INSTANCE
// this would be the ideal form to have working
DATABASE_URL="sqlserver://DESKTOP-F3USMA8\SQLEXPRESS;database=prisma;integratedSecurity=true;trustServerCertificate=true;"
DATABASE_URL="sqlserver://DESKTOP-F3USMA8\MSSQLSERVER;database=prisma;integratedSecurity=true;trustServerCertificate=true;"
DATABASE_URL="sqlserver://DESKTOP-F3USMA8\SQLEXPRESS:2584;database=prisma;integratedSecurity=true;trustServerCertificate=true;"
DATABASE_URL="sqlserver://localhost\SQLEXPRESS:2584;database=prisma;integratedSecurity=true;trustServerCertificate=true;"
Here are connection strings that worked:
// the ports and instances are in the pictures above
// connects to the SQL Express instance
DATABASE_URL="sqlserver://localhost:2584;database=prisma;integratedSecurity=true;trustServerCertificate=true;"
// connects to the SQL Server instance
DATABASE_URL="sqlserver://localhost:2584;database=prisma;integratedSecurity=true;trustServerCertificate=true;"
// connects to the SQL Server instance
DATABASE_URL="sqlserver://DESKTOP-F3USMA8;database=prisma;integratedSecurity=true;trustServerCertificate=true;"
From this, I can see that the named instance connection string are not working.
I could probably test it on my laptop too, with a fresh installation of windows.
How to reproduce
Using
npx prisma db push
creates this error:
Error creating a database connection.
Expected behavior
Prisma establishes connection to the SQL Server DB with a named instance.
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}
model Post {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String @db.VarChar(255)
}
Environment & setup
- OS: Windows 11/10
- Database: SQL Server (Developer, Express)
- Node.js version: 18.7.0
Prisma Version
prisma : 4.2.1
@prisma/client : 4.2.1
Current platform : windows
Query Engine (Node-API) : libquery-engine 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine : migration-engine-cli 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt 2920a97877e12e055c1333079b8d19cee7f33826 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : 2920a97877e12e055c1333079b8d19cee7f33826
Studio : 0.469.0
Issue Analytics
- State:
- Created a year ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
Actually, now when I’m looking at this once more, this is a bug of a feature that should work.
Hey, to clarify I want to use a named instance of a server, to connect through tcp.
I tried your suggestion with these options, and none of them work (find the port with the method from above):
Errors out with: Error parsing connection string: Conversion error: Invalid instance name in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters."
Errors out with: invocation:\n\n\nError creating a database connection. (Error creating a database connection.)"