R
Railway15mo ago
Matías

API requests to postgreSQL database not responding

82 Replies
Percy
Percy15mo ago
Project ID: b4194196-508c-46f3-955a-fba9c4fd5daf
Matías
Matías15mo ago
b4194196-508c-46f3-955a-fba9c4fd5daf
Brody
Brody15mo ago
have you set up the environment variables correctly and are using them properly in code?
Matías
Matías15mo 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
Brody15mo ago
can't you connect to the database with something like pgadmin
Matías
Matías15mo ago
how i can do that?
Brody
Brody15mo ago
download pgadmin and try to connect
Matías
Matías15mo ago
i have pgadmin
Brody
Brody15mo ago
then let me know if you can connect to your database with it
Matías
Matías15mo ago
okay thanks, i will try I manage to connect it but i cant see any tables
Brody
Brody15mo ago
are there supposed to be tables
Matías
Matías15mo ago
sorry, my mistake they are here
Brody
Brody15mo 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ías15mo ago
"ConnectionStrings": { "DefaultConnection": "Host=containers-us-west-10.railway.app; Database=railway; Username=postgres; Password=fLcUiLbPfdP4nJJIyOJw" }
Brody
Brody15mo ago
you are not using environment variables
Matías
Matías15mo 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
Brody15mo ago
please use environment variables
Matías
Matías15mo ago
the values that im using are from the environment variables
Brody
Brody15mo ago
you should not be copy pasting any secrets like you are doing now
Matías
Matías15mo ago
okay, but apart from the security why is it not working now
Brody
Brody15mo ago
database credentials should not be stored in plaintext because you aren't using environment variables
Matías
Matías15mo 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
Brody15mo ago
please show me a screenshot of your service variables
Matías
Matías15mo ago
these? Available Variables This plugin exposes the following variables. DATABASE_URL ** PGDATABASE ** PGHOST ** PGPASSWORD ** PGPORT ** PGUSER **
Brody
Brody15mo ago
a screenshot that's a screenshot of the plugin, show me a screenshot of your service variables
Matías
Matías15mo ago
in my code?
Brody
Brody15mo ago
your service variables in the railway ui
Matías
Matías15mo ago
in which part of railway?
Brody
Brody15mo ago
bruh
Matías
Matías15mo ago
Im so sorry im new in railway
Brody
Brody15mo ago
in your service, the variables tab, show me a screenshot
Matías
Matías15mo ago
thats why i dont really know
Brody
Brody15mo ago
it's not like I'm speaking gibberish
Matías
Matías15mo ago
port is 5000 my bad, sorry
Brody
Brody15mo ago
you need to setup the variable references https://docs.railway.app/develop/variables#reference-variables
Matías
Matías15mo ago
Okay perfect! I will check that docs thanks for the help @Brody I appreciate it
Brody
Brody15mo ago
once you get that setup, please show me another screenshot like the one you just sent
Matías
Matías15mo ago
perfect! 🙌 Hi! what should i do now?
Brody
Brody15mo ago
please use variable references also dont show me your password, please go and regen your credentials
Matías
Matías15mo ago
Okay but the variables are good?
Brody
Brody15mo ago
they are not ^ ^
Matías
Matías15mo ago
i saw the docs but they dont especify that
Brody
Brody15mo ago
you did not read the docs
Matías
Matías15mo ago
I really did but i dont understand how should i call my variables
Brody
Brody15mo ago
^ do that before we move on
Matías
Matías15mo 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
Brody15mo ago
show me a full browser screenshot
Matías
Matías15mo ago
okay i will
Brody
Brody15mo ago
of your project
Matías
Matías15mo ago
first look this railway does not suggest me any name
Brody
Brody15mo ago
well yeah of course not, where is your database?
Matías
Matías15mo ago
im showing you this because you will think im lying, but im not
Brody
Brody15mo ago
i dont think youre lying, youre just being silly lol
Matías
Matías15mo ago
Im asking beacause im new here, i never uploaded an app to a server and i want to learn
Brody
Brody15mo 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ías15mo 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
Brody15mo ago
beautiful
Matías
Matías15mo ago
now its supposed to work? or i also need to change my code?
Brody
Brody15mo ago
show me how you are using environment variables in your code
Matías
Matías15mo ago
okay this was my last database now im using a new one
Brody
Brody15mo ago
you need to use environment variables in code
Matías
Matías15mo ago
okay so i dont type any value in the code
Brody
Brody15mo ago
right, you should never do what you just did
Matías
Matías15mo ago
perfect, i will try now, thanks!!
Brody
Brody15mo ago
and show me code when your done
Matías
Matías15mo ago
okay DefaultConnection": "Host=${Postgres.PGHOST}; Database=${Postgres.PGDATABASE}; Username=${Postgres.PGUSER}; Password=${Postgres.PGPASSWORD}
Brody
Brody15mo ago
nope nodejs right?
Matías
Matías15mo ago
nope, .net 6 thats not okay?
Brody
Brody15mo ago
then lookup how to get environment variables in dotnet
Matías
Matías15mo ago
my env variables in my code should have the same name as in the last photo (ex: PGDATABASE)?
Brody
Brody15mo ago
yes though, you are missing some
Brody
Brody15mo ago
Matías
Matías15mo 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
Brody15mo 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ías15mo ago
there is not much info about env i .net
Brody
Brody15mo ago
i cant help that
Matías
Matías15mo ago
yes but i only added the ones i used before to coonect to my database localy i need all of them now?
Brody
Brody15mo ago
yes but first and foremost you need to use environment variables USE ENVIRONMENT VARIABLES
Matías
Matías15mo 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
Brody15mo ago
no further questions until you are using environment variables
alex
alex15mo ago
Brody
Brody15mo ago
how did i know