timeout errors when trying to configure azure mysql to railway backend
has anyone experienced time out errors in railway when fetching things from a azure database? Currently in development it works fine in fetching from the database in mysqlWorkbench, so i do know the connection is working
However, when i put it in a railway server it is unable to access to any data of the database at all in azure right now. Maybe it is due to how i initialized my connection?
Sorry, im super new, so any help would be appreciated!
some relevant code trying to make connection to the azure SQL:
<-code below->
const mysql = require('mysql2');
const fs = require('fs');
const dotenv = require('dotenv');
dotenv.config();
// Configuration object for your SQL Server connection
const configurations= {
host: process.env.HOST,
database: process.env.DATABASE,
user: process.env.CLIENT,
password: process.env.PASSWORD,
port: process.env.PORT,
ssl:{ca:fs.readFileSync(process.ev.URL)},
/* waitForConnections: true,
connectTimeout: 60000,
queueLimit: 0,
*/
};
const db = mysql.createConnection(configurations).promise();
module.exports = db;
31 Replies
Project ID:
N/A
N/A
please enclose all code in triple backticks
Gotcha
I’m not sure but maybe the environment variables I defined in railway may have caused a problem,as I defined for example for process.env.host as HOST=(myhostname) in the variables
Triple backticks
Misspelt “env” with “ev”
I saw but I'm more confused at why they're trying to read a file from a url environment variable
Yeah…
Oh yeah I’m new to azure so let me clarify
I’d suggest either putting the file in the repo or using axios to get the file from the URL so it’ll download it
I think it was one of the authentication methods azure used
Yeah, certificates
Oh yeah that’s a typo in my part when sending this code, I didn’t want to send the Actual file path
I wonder if it was a conflict with having MySQL workbench online at the same time but I doubt it
Should’ve just set it to “PATH” or misc, looks like an additional error on our ends
There’s no firewall settings on any of those services, right?
Shoot there is
I only enabled my IP I think
can you please give all these correct variable names?
HOST
-> AZURE_HOST
DATABASE
-> AZURE_DATABASE
and so on, i believe once you have your variables named correctly it could work, or at the very least, rule out possible conflicting variable namesThe only one I think could conflict is the port name
exactly
I used 3306
please name your variables properly and get back to us
Ok so I established connection to azure sql and I successfully was able to get access to the data in my server
So basically the railway server is successfully connected but now the problem I think lies in post requests now
what's the issue with post requests?
I’ll send my code once I get back but I am getting null when making them and getting no response as well as a blank screen. There’s probably something wrong in my frontend and post request
I deployed my frontend on netlify
are you making sure to make your requests with https
Yes
I’m making a cookies request in the code do you think the it may cause conflict?
there is some funky stuff with cross origin cookies, id recommend watching some YouTube videos on the subject
Alright gotcha
Here’s what it I’m doing whenever I’m trying to authenticate users,
I've never done jwt auth in any context, YouTube would be a much better help there, especially since this isn't super railway related
ok thanks, just one more question since i was able solve all the issues except for one
this isnt railway related but I just wanted to know if youve had experience with uploading images to database. I was working with multer and was wondering how to display the images in a production setting(since it dosent have a file path in production that the images are saved onto). Im wondering if theres a possible way to avoid this
well first you dont want to put images in a database, you want to use a volume https://docs.railway.app/guides/volumes
and then heres a multer example that uses railways volumes https://github.com/brody192/multer-file-uploads
ok thank you!