@harshgoyal3823 , If you are using free
@harshgoyal3823 , If you are using free tier of NeonDB then it downscales itself in five minutes, That's why it might not be working for you, Consider it like that if you are not using your database for five minutes then your machine gets shutdown and you again have to connect to database
33 Replies
equal-aqua•15mo ago
@Not-Qualified But I am connecting to database in every request that I am making
manual-pink•15mo ago
Can you show me your connection part ?
equal-aqua•15mo ago
Its at the top of the handlesignup function.
@Not-Qualified
See that there is const db = neon(process.env.DATABASE_URL as string)
manual-pink•15mo ago
Is neon() is custom function or something that neonDB provides with it's library ?
equal-aqua•15mo ago
Its provided by neon
import { neon } from '@neondatabase/serverless';
manual-pink•15mo ago
Got it
Check your connection string
It's correct or not
That would be first step
equal-aqua•15mo ago
It is correct. In case of Select * from users, the connection works also
manual-pink•15mo ago
Meaning if you put SELECT statment within db() then it's working and it's only not working for INSERT statement, Correct ?
I guess, your
db
variable is getting confused here, Is it?equal-aqua•15mo ago
Its working now for Insert also, I am literally confused, its working sometimes and sometimes it is not. I dont know what is the reason
manual-pink•15mo ago
Good, Then
For free tier, There's limit for connections and compute resources, So, mind that
equal-aqua•15mo ago
I would assume so, I think it is related to neon tech free tier maybe. I dont know how can I resolve it though
manual-pink•15mo ago
equal-aqua•15mo ago
where to use it?
manual-pink•15mo ago
This is as many connections that NeonDB can handle and it will tell you that how many currently are active connection to database are there
Use it directly in Neon Console
equal-aqua•15mo ago
yeah got it, but my current connections are way less than mex allowed
manual-pink•15mo ago
As you are saying that your queries sometimes working and sometimes don't is it happening very frequently ?
Are you able to reproduce this on every other requests ?
equal-aqua•15mo ago
maybe that's why its working fine. Do we have any function to close the connection once the result is returned? I checked for it, couldnt find it
It is happening very frequently, though for now, it seems to work fine. Maybe some compute issue only.
manual-pink•15mo ago
If it happens again, I would suggest that you record video and post it here and tag anyone from Neon Team
They will surely look into it
They are very active
equal-aqua•15mo ago
Thanks for the help. really appreciate it. Saved me after 6hrs of frustration
manual-pink•15mo ago
In which region your project is ?
equal-aqua•15mo ago
US east
manual-pink•15mo ago
Looks like your personal project
You working on sunday
equal-aqua•15mo ago
More like a Take home assignment, have to submit it tomorrow
manual-pink•15mo ago
College Student ?
equal-aqua•15mo ago
Nope, working professional
manual-pink•15mo ago
I'm backend engineer
equal-aqua•15mo ago
I am a frontend engineer
manual-pink•15mo ago
Frontend engineer working with database ?, Sounds like you are on your journey to being the full stack guy
frozen-sapphire•15mo ago
So this isn't really related to the free tier. And I don't think it's related to connection limits. (Just make sure you're using the pooled connection string)
Its working now for Insert also, I am literally confused, its working sometimes and sometimes it is not. I dont know what is the reasonNot sure tbh why you ran into an issue specifically with inserts 🤔 Glad it's working though This shows the number of connections when using the non-pooled connection string
equal-aqua•15mo ago
Ok, I was not using the pooled connection. Is there any specific reason to use pooled connection string?
frozen-sapphire•15mo ago
If you're gonna deploy your Next.js app to a serverless platform (e.g Vercel), your API endpoints become serverless functions. When querying your database from those environments, each function invocation will open a new connection to the database. This process is slow and resource-intensive.
So the solution is to connect via a connection pooler. (this is managed for you by Neon and it's exposed via the pooled connection string). It maintains a pool of connections that can be reused to avoid this issue.
equal-aqua•15mo ago
Got it, thanks
This is still persisting, I changed to pool connection string, but still getting connection timeout error
extended-yellow•15mo ago
Hey @harshgoyal3823,
Can you share your updated code?