falah mahmood
falah mahmood

Reputation: 465

Can not connect to Neon using Prisma

I created a new NextJs(v14) app, installed prisma(v5.16.1) and then created a new project on Neon. I have added a .env file in my project and copied the Neon database connection string to it.

The connection string is: postgresql://[user]:[password].us-east-2.aws.neon.tech/expensedb?sslmode=require

I have added two models to the schema.primsa file. When I run "npx prisma generate" I get no erros. Afterwards, when I run "npx prisma migrate dev" I get a connection timed out error.

Error: P1001: Can't reach database server at ep-dark-frog-a501j4x2.us-east-2.aws.neon.tech:5432
Please make sure your database server is running at ep-dark-frog-a501j4x2.us-east-2.aws.neon.tech:5432.

I tried adding connect_timeout=300 to the connection string but then the connection just hangs.

Can someone please help with this...

If possible, please recreate the steps I have taken above and see if you run into the same issue.

Upvotes: 1

Views: 1304

Answers (2)

Tabot Charles Bessong
Tabot Charles Bessong

Reputation: 47

The issue you are facing has to deal with the formatting of your DATABASE_URL value in your .env file. What you need to do is add a ? and a timeout command after your url

update the value in your .env file like this

DATABASE_URL = 'url + ?sslaccept=strict&connect_timeout=500'

Upvotes: 0

falah mahmood
falah mahmood

Reputation: 465

So after trial and error I've found a working solution.

In the neon.tech home screen, go to the "overview" tab in the sidebar and select "Roles & Databases" tab. From there, create a new Role and a new Database, and then use the new details to generate the connection string from the "Dashboard" tab in the sidebar. Following this approach, I am not getting any errors and my connection doesn't hang either. Also note, I did not need to use the "connect_timeout" parameter in the connection string.

If anyone else was having this issue, hopefully this solution works for you too.

Upvotes: 0

Related Questions