Reputation: 199
I have a node/express project using Prisma. The db is SqlServer. I went through all the setup. All the associated tools are working fine. From the CLI: prisma generate
& prisma migrate
& prisma introspect
all work perfectly using my schema.prisma file. Prisma Studio, using the exact same schema file, connects just fine and interacts with the db, no problems. Similarly, Azure Data Studio connects with to the db easily, using the same the exact same host/user/password. But when I try to use the PrismaClient (for example using findMany
), it gives an error: Invalid prisma.user.findMany() invocation: Error creating a database connection.
I am on a Mac - Big Sur 11.3.1
The SqlServer is running in a separate docker container and I can access it in multiple ways with no problem.
schema.prisma (working fine for everything EXCEPT the Prisma Client)
generator client {
provider = "prisma-client-js"
previewFeatures = ["microsoftSqlServer"]
}
datasource db {
provider = "sqlserver"
url = env("DATABASE_URL")
}
model User {
id Int @id @default(autoincrement())
email String @unique
password String
}
users.service.ts
import { PrismaClient, User } from '@prisma/client';
class UserService {
public users = new PrismaClient().user;
public async findAllUser(): Promise<User[]> {
const allUser: User[] = await this.users.findMany();
return allUser;
}
}
Upvotes: 0
Views: 3638
Reputation: 199
ok, so I found at least part of the answer. I had been running my Prisma/Node project in a Docker container via docker-compose
. If I, instead, just run it via npm run dev
then the PrismaClient works fine! No idea why it can't connect to my db when inside a container...
Upvotes: 0