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