question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PrismaClientInitializationError: Server has closed the connection. SQLServer 2016

See original GitHub issue

Bug description

I am unable to connect to our SQLServer 2016 using prisma: I am using prisma 3.14.0. We want to migrate from typeorm, which can connect to the DB just fine.

Our connection string looks like this:

DATABASE_URL="sqlserver://<host>:1433;user=<user>;password=<password>;database=<DB_NAME>;encrypt=false;integratedSecurity=false;trustServerCertificate=true"

When I try to run prisma db pull I get the following error:

yarn prisma db pull 
yarn run v1.22.18
$ /Users/jan/Dev/monorepo/node_modules/.bin/prisma db pull
  prisma:engines binaries to download libquery-engine, migration-engine, introspection-engine, prisma-fmt +0ms
Prisma schema loaded from prisma/schema.prisma
  prisma:loadEnv project root found at /Users/jan/Dev/monorepo/package.json +0ms
  prisma:tryLoadEnv Environment variables loaded from /Users/jan/Dev/monorepo/.env +0ms
Environment variables loaded from .env
  prisma:getConfig Using CLI Query Engine (Node-API Library) at: /Users/jan/Dev/monorepo/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node +0ms
Datasource "db" - SQL Server
  prisma:getConfig Using CLI Query Engine (Node-API Library) at: /Users/jan/Dev/monorepo/node_modules/@prisma/engines/libquery_engine-darwin.dylib.node +12ms

⠋ Introspecting based on datasource defined in prisma/schema.prisma  prisma:introspectionEngine:rpc starting introspection engine with binary: /Users/jan/Dev/monorepo/node_modules/@prisma/engines/introspection-engine-darwin +0ms
  prisma:introspectionEngine:rpc SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"introspect","params":[{"schema":"// This is your Prisma schema file,\n// learn more about it in the docs: https://pris.ly/d/prisma-schema\n\ngenerator client {\n  provider = \"prisma-client-js\"\n}\n\ndatasource db {\n  provider = \"sqlserver\"\n  url      = env(\"DATABASE_URL\")\n}\n\nmodel User {\n  id        Int @id @default(autoincrement())\n  name      String\n  email     String\n  password  String\n}\n","compositeTypeDepth":-1}]} +12ms
⠴ Introspecting based on datasource defined in prisma/schema.prisma  prisma:introspectionEngine:rpc {
  prisma:introspectionEngine:rpc   jsonrpc: '2.0',
  prisma:introspectionEngine:rpc   error: {
  prisma:introspectionEngine:rpc     code: 4466,
  prisma:introspectionEngine:rpc     message: 'An error happened. Check the data field for details.',
  prisma:introspectionEngine:rpc     data: {
  prisma:introspectionEngine:rpc       is_panic: false,
  prisma:introspectionEngine:rpc       message: 'Error in connector: Error querying the database: Error querying the database: The server terminated the connection.',
  prisma:introspectionEngine:rpc       backtrace: null
  prisma:introspectionEngine:rpc     }
  prisma:introspectionEngine:rpc   },
  prisma:introspectionEngine:rpc   id: 1
  prisma:introspectionEngine:rpc } +447ms
✖ Introspecting based on datasource defined in prisma/schema.prisma

Error: Error: Error in connector: Error querying the database: Error querying the database: The server terminated the connection.

    at Object.<anonymous> (/Users/jan/Dev/monorepo/node_modules/prisma/build/index.js:51989:29)
    at Object.handleResponse (/Users/jan/Dev/monorepo/node_modules/prisma/build/index.js:51867:38)
    at LineStream4.<anonymous> (/Users/jan/Dev/monorepo/node_modules/prisma/build/index.js:51945:20)
    at LineStream4.emit (node:events:527:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at LineStream4.Readable.push (node:internal/streams/readable:228:10)
    at LineStream4._pushBuffer (/Users/jan/Dev/monorepo/node_modules/prisma/build/index.js:51710:21)
    at LineStream4._transform (/Users/jan/Dev/monorepo/node_modules/prisma/build/index.js:51704:12)
    at LineStream4.Transform._write (node:internal/streams/transform:184:23)
error Command failed with exit code 1.

How to reproduce

  • Setup like above with SQLServer 2016
  • Try to connect to the DB

Expected behavior

Connection should be established

Prisma information

The datasource configuration looks like this:

datasource db {
  provider = "sqlserver"
  url      = env("DATABASE_URL")
}

Environment & setup

  • OS: Mac OS
  • Database: SQLServer 2016 (13.0.63)
  • Node.js version: 16.15.0

Prisma Version

prisma                  : 3.14.0
@prisma/client          : 3.14.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 2b0c12756921c891fec4f68d9444e18c7d5d4a6a
Studio                  : 0.460.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pip8786commented, May 24, 2022

Yep, just tested it this morning, all other conditions were the same.

0reactions
janpiocommented, Jun 3, 2022

The relevant part if in Migration or Introspection Engine, relevant diff is here: https://github.com/prisma/prisma-engines/compare/3.12.0...3.13.0 Connection logic is probably pulled in via a dependency, quaint and/or tiberius (our SQL Server driver).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error message reference - Prisma
PrismaClientInitializationError. Prisma Client throws a PrismaClientInitializationError exception if something goes ... "Server has closed the connection.
Read more >
"Authentication failed for user" when running prisma db pull on ...
I created a new DB user with proper rights (that I can log in to SQL Server Management Studio with). However, it does...
Read more >
HOW TO FIX CANNOT CONNECT TO SQL SERVER ERROR
ADDITIONAL INFORMATION: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was ...
Read more >
An existing connection was forcibly closed by the remote host ...
In this tip we look at how to troubleshoot and fix SQL Server Service Broker error receiving data 10054 existing connection was forcibly ......
Read more >
Encrypting Connections to SQL Server on Linux
SQL Server on Linux can use Transport Layer Security (TLS) to encrypt data that is transmitted across a network between a client application ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found