Trouble connecting to MySQL database form a seperate computer
I'm learning C# by making my own Chat app. And I want to use a database (MySQL) for storing usernames and passwords (IK not safe maybe). But i'm having trouble connecting to it. Any idea why?
36 Replies
whats the specific error u r getting, connection refused?
Also, where's the database, exactly? Another PC on the same LAN? another PC on a different network? Something else?
I'm on a seperate wifi connection. DB is on a VPS
so its on the internet, u should first of all set a good password for the root, and also create an limited account (with a good password) for that one scheme
to plug that big fat security hole u have there
an which line of code the exception is thrown?
It's not within my code but from something else. Imma take a little break real quick. Just to clear my mind
the stacktrace of
Inner Exception 1: MySqlException
is the interesting part hereAlright hold on. Give me like 5 mins
And I'll come back it look into it
I'm back
⤴️
I think this is from me doing the connection wrong
Inner Exception 1:
MySqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
well, thats why i asked for the stacktrace, the error message i can read already
Call Stack?
thats the call stack/stacktrace from the outer exception (the
AggregateException
), i need the one from the inner MySqlException
How would I find that?
while the execution is paused on
u can inspect the locals, that includes the
exceptionList
, the first element should be the MySqlException
that should have a StackTrace
property (the string content will look a bit weird with \n
in there, just copy that all and paste it here)Yeah I sent the screenshots
Here
yeah and thats not showing the stacktrace...
gimme a sec to prepare a screenshot
that one is what im talking about
Ok well I'm not getting that anymore. I'm now getting this
actually if ya click on
View Details
u should be able to see a similar windowguess ur db isnt reachable from the outside
Well I did it b4 in Node.js
I think
was that from ur local machine or from the vps?
VPS
yeah and now u r running from local machine right?
usually dbs are configured to only listen for connections on the local machine they r running on, in this case the vps and not ur machine
So that means I would have to have a server in my house?
Bc if so I can bring out an old laptop
But that would cause security risks
well, unless u run the db on the same machine as ur application u will have that risk.
a machine in ur local network would be safer tho because not the whole internet could try to connect to it
Ok I'll do that then
so i would go for the route:
- set up that old laptop in ur local network
- install mysql and give root a proper password
- create a schema for ur application
- create a user that has only access to that schema and has another proper password
- configure the mysql server to listen on any ip, not just localhost (which is the default)
and then u should be able to use it
the mysql
root
user should stay to only be able to login from localhost (u can set up ssh to log into it if required, passkeys are more secure anyway)
the mysql user for that one schema can be set up to be able to log in from any ip, this is then also the one u will be using for ur applicationOk I just setup my laptop and xampp (MySQL) server. and still failed
I'm still looking on the internet for a solution
as said u still have to configure mysql to listen on any ip instead of just localhost
I did it. Whole time I was using public IP
Finally
Well it only works if I'm a VPN. Gotta do some more testing and coding