API requests to postgreSQL database not responding

82 Replies
Percy
Percy2y ago
Project ID: b4194196-508c-46f3-955a-fba9c4fd5daf
Matías
MatíasOP2y ago
b4194196-508c-46f3-955a-fba9c4fd5daf
Brody
Brody2y ago
have you set up the environment variables correctly and are using them properly in code?
Matías
MatíasOP2y ago
Yes! First i was connected to my database from my computer, then i changed all the variables to the ones that railways gives me when i create the database and its not woekinmg
Brody
Brody2y ago
can't you connect to the database with something like pgadmin
Matías
MatíasOP2y ago
how i can do that?
Brody
Brody2y ago
download pgadmin and try to connect
Matías
MatíasOP2y ago
i have pgadmin
Brody
Brody2y ago
then let me know if you can connect to your database with it
Matías
MatíasOP2y ago
okay thanks, i will try I manage to connect it but i cant see any tables
Brody
Brody2y ago
are there supposed to be tables
Matías
MatíasOP2y ago
sorry, my mistake they are here
Brody
Brody2y ago
okay so if pgadmin can connect there's nothing wrong with the database, you are probably just using the variables incorrectly please show me a screenshot of your service variables
Matías
MatíasOP2y ago
"ConnectionStrings": { "DefaultConnection": "Host=containers-us-west-10.railway.app; Database=railway; Username=postgres; Password=fLcUiLbPfdP4nJJIyOJw" }
Brody
Brody2y ago
you are not using environment variables
Matías
MatíasOP2y ago
when i was using the local database, i didnt pass the port, i was passing only host, database, username and password what do you mean?
Brody
Brody2y ago
please use environment variables
Matías
MatíasOP2y ago
the values that im using are from the environment variables
Brody
Brody2y ago
you should not be copy pasting any secrets like you are doing now
Matías
MatíasOP2y ago
okay, but apart from the security why is it not working now
Brody
Brody2y ago
database credentials should not be stored in plaintext because you aren't using environment variables
Matías
MatíasOP2y ago
they dont work if they are like that? okay i will see how to do it, thanks for this info, i didnt know
Brody
Brody2y ago
please show me a screenshot of your service variables
Matías
MatíasOP2y ago
these? Available Variables This plugin exposes the following variables. DATABASE_URL ** PGDATABASE ** PGHOST ** PGPASSWORD ** PGPORT ** PGUSER **
Brody
Brody2y ago
a screenshot that's a screenshot of the plugin, show me a screenshot of your service variables
Matías
MatíasOP2y ago
in my code?
Brody
Brody2y ago
your service variables in the railway ui
Matías
MatíasOP2y ago
in which part of railway?
Brody
Brody2y ago
bruh
Matías
MatíasOP2y ago
Im so sorry im new in railway
Brody
Brody2y ago
in your service, the variables tab, show me a screenshot
Matías
MatíasOP2y ago
thats why i dont really know
Brody
Brody2y ago
it's not like I'm speaking gibberish
Matías
MatíasOP2y ago
port is 5000 my bad, sorry
Brody
Brody2y ago
you need to setup the variable references https://docs.railway.app/develop/variables#reference-variables
Matías
MatíasOP2y ago
Okay perfect! I will check that docs thanks for the help @Brody I appreciate it
Brody
Brody2y ago
once you get that setup, please show me another screenshot like the one you just sent
Matías
MatíasOP2y ago
perfect! 🙌 Hi! what should i do now?
Brody
Brody2y ago
please use variable references also dont show me your password, please go and regen your credentials
Matías
MatíasOP2y ago
Okay but the variables are good?
Brody
Brody2y ago
they are not ^ ^
Matías
MatíasOP2y ago
i saw the docs but they dont especify that
Brody
Brody2y ago
you did not read the docs
Matías
MatíasOP2y ago
I really did but i dont understand how should i call my variables
Brody
Brody2y ago
^ do that before we move on
Matías
MatíasOP2y ago
Reference Variables Variables can use the ${{VAR}} or ${{NAMESPACE.VAR}} syntax to reference other service variables, shared variables, or plugin variables. The Railway dashboard provides an autocomplete dropdown in both the name and value fields to help create these references. Railway does not autocomplete the names for me that´s why i create the variables with that names
Brody
Brody2y ago
show me a full browser screenshot
Matías
MatíasOP2y ago
okay i will
Brody
Brody2y ago
of your project
Matías
MatíasOP2y ago
first look this railway does not suggest me any name
Brody
Brody2y ago
well yeah of course not, where is your database?
Matías
MatíasOP2y ago
im showing you this because you will think im lying, but im not
Brody
Brody2y ago
i dont think youre lying, youre just being silly lol
Matías
MatíasOP2y ago
Im asking beacause im new here, i never uploaded an app to a server and i want to learn
Brody
Brody2y ago
why do you have the database in a seprate project create a new database in the same project as the service that is accessing it
Matías
MatíasOP2y ago
the video i saw on youtube was like that i didnt know that you can have all in the same project i will manage that now thanks Done
Brody
Brody2y ago
beautiful
Matías
MatíasOP2y ago
now its supposed to work? or i also need to change my code?
Brody
Brody2y ago
show me how you are using environment variables in your code
Matías
MatíasOP2y ago
okay this was my last database now im using a new one
Brody
Brody2y ago
you need to use environment variables in code
Matías
MatíasOP2y ago
okay so i dont type any value in the code
Brody
Brody2y ago
right, you should never do what you just did
Matías
MatíasOP2y ago
perfect, i will try now, thanks!!
Brody
Brody2y ago
and show me code when your done
Matías
MatíasOP2y ago
okay DefaultConnection": "Host=${Postgres.PGHOST}; Database=${Postgres.PGDATABASE}; Username=${Postgres.PGUSER}; Password=${Postgres.PGPASSWORD}
Brody
Brody2y ago
nope nodejs right?
Matías
MatíasOP2y ago
nope, .net 6 thats not okay?
Brody
Brody2y ago
then lookup how to get environment variables in dotnet
Matías
MatíasOP2y ago
my env variables in my code should have the same name as in the last photo (ex: PGDATABASE)?
Brody
Brody2y ago
yes though, you are missing some
Brody
Brody2y ago
Matías
MatíasOP2y ago
Brody im having a problem, i have been researching and they told me that in .net the env variables are setted in the appsettings.json and i did it like this
Brody
Brody2y ago
you have to stop using the credentials as plaintext that it not how you use environment variables in a dotnet app
Matías
MatíasOP2y ago
there is not much info about env i .net
Brody
Brody2y ago
i cant help that
Matías
MatíasOP2y ago
yes but i only added the ones i used before to coonect to my database localy i need all of them now?
Brody
Brody2y ago
yes but first and foremost you need to use environment variables USE ENVIRONMENT VARIABLES
Matías
MatíasOP2y ago
yes i know im trying to see how to do it .net is a mess but meanwhile i wanted to know if i also need to pass any other value to this connection apart from the ones i mentioned before
Brody
Brody2y ago
no further questions until you are using environment variables
alex
alex2y ago
Brody
Brody2y ago
how did i know
Want results from more Discord servers?
Add your server