#Troubleshooting Connection String Error in Page Context for SQL Query Execution

144 messages · Page 1 of 1 (latest)

bold moatBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

noble oxide
#

I have a SQL query that works perfectly in routes, but encounters an issue when used on a page. The query is as follows:

const sqlResponse = await sql` SELECT * FROM Profiles WHERE ProfileID = ${params.profile}; `;

This is executed in an environment defined by .env.development.local. However, when I try to use this SQL query in a page, I encounter an error stating: 'Error fetching data: VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found.

young maple
noble oxide
#

it works pefectly fine when using routes

#

but somehow not in pages

young maple
noble oxide
#

"undefined"

young maple
noble oxide
#

i only have these

#

ok so i copied this and pasted it

#

still its "undefined"

young maple
noble oxide
#

no idea it works in routes tho

#

just not in pages

young maple
#

are you on dev mode?

noble oxide
#

yep

young maple
noble oxide
young maple
noble oxide
young maple
noble oxide
young maple
noble oxide
#

yea

#

removing it changes nothing tho

young maple
noble oxide
#

(after removing the other .env)

young maple
noble oxide
#

it did work

young maple
noble oxide
#

yea

young maple
#

and which on did you put POSTGRES_URL?

noble oxide
#

.env

#

well before .env.development..

#

but then u said .env

young maple
#

try moving it to .env.development.local

#

if NODE_ENV is development and you define a variable in both .env.development.local and .env, the value in .env.development.local will be used.

noble oxide
#

same error

young maple
#

restart the server

noble oxide
young maple
noble oxide
#

yes

#

same error still

young maple
#

lol

#

i don't know

#

just use .env then lol

noble oxide
#

same error

young maple
#

.env doesn't work too now?

noble oxide
#

nope

#

this is so weord

young maple
#

restart the server

noble oxide
#

i did

young maple
#

did it load from .env now

noble oxide
#

yea but same error

#

is it because of "use client"

young maple
noble oxide
#

yea

young maple
#

you can't use it in client component

noble oxide
#

hm

#

how i should use it then? without using routes

young maple
#

without 'use client'

noble oxide
#

like this?

young maple
#

yes if you gonna use this with server action

noble oxide
#

and display it on the site

#

without using any api

young maple
#

everything are server by default

#

unless you mark it to client

noble oxide
#

when i dont put "use server"

#

same error comes back

young maple
noble oxide
#

well it works they way im using it

#

so all good

#

works perfectly fine

young maple
#

when mean you are fetching with server action

#

on client side

#

all good if this is what you want

noble oxide
#

yea

#

i just want the data to be leaked

young maple
#

ok cool

noble oxide
#

like the proflile contains secretKey

#

thats what shouldnt be public

young maple
#

no, your key not gonna leak

#

but seo engine will not be able to crawl your site

noble oxide
#

thats totally fine

#

thanks bro

young maple
#

ok no prob

bold moatBOT
#
✅ Success!

This question has been marked as answered! If you have any other questions, feel free to create another post

Jump to answer

[Click here](#1201905761618231337 message)

noble oxide
#

@young maple

#

It shows in the network still

young maple
noble oxide
young maple
noble oxide
#

not possible to hide?

young maple
#

what you gonna do with this data

#

fetch on server

noble oxide
#

display it

#

nothing else

young maple
#

why would you wanna hide it if you gonna display it?

#

it will show on the dom anyway?

noble oxide
#

bcs some of the columns shouldnt not gonna be displayed

#

only some parts

young maple
#

only select the column you need

noble oxide
#

not possible any other way?

young maple
#

fetch on server

noble oxide
#

wdym

young maple
#

no other way

#

don't fetch on client

young maple
noble oxide
#

well i fetch it on "use server" and just pass the data to the client

young maple
#

you are fetching on client side

#

with server action

noble oxide
#

how i should do it? can you give me an example

young maple
#

remove 'use client'

noble oxide
#

ahh this is so bad

young maple
noble oxide
#

i dont get it how i should split the files with "use xxx"

#

its weird asf

young maple
#

you don't even need 'use client' useState setData useEffect if you fetch on server

young maple
noble oxide
#

i use useEffect to add views to the user

young maple
#

much simple

noble oxide
#

and loading screen