Cant connect to mysql server when port is change c# - c#

Im using xammp as my platform for my database
Usually the defualt port of mysql is 3306 and it is working properly
But when I change the port like 4444 in my.ini I have an error message receive
cannot connect to any of the specified mysql hosts
By using this connection string
string connectString = "datasource=xxx.xx.xx.xxx;port=4444;username=root;password="";database=XXXXX;";

Well XAMPP might require a restart of MySQL server in order to update open port. But according to Connector strings, parameter "Port" might be ignored if Unix socket is used. So you can also check that.
Also, I know that have PHP in title, but I think it might be connected with your problem. Try this and say if it helped

Related

How do I connect to my Google cloud SQL instance with C#?

I am trying to use visual studio to write a program in c# and have it connect to my google cloud sql server. Unfortunately I have been trying to troubleshoot it and have had no luck. I already added my IP and my connection works through MYSQL Workbench.
I attempted to connect with the whole data source, network library, initial catalog, etc. I tried it without the network library and used the proper way to escape \ in the string during the connection. I also tried the default 1433 port and 3306. No luck.
// Build Connection String
SqlConnection clearviscon = new SqlConnection(#"Server=xx.xx.xx.xx\alpine-park-243102:us-central1:xxx, 3306;Network Library=DBMSSOCN;Initial Catalog=xxdatabase;User ID=root;Password=xxx123");
clearviscon.Open();
To connect to Google Cloud SQL for MySQL, you must use a MySQL client library. I recommend MySqlConnector.
Your connection string will be Server=xx.xx.xx.xx;Database=xxdatabase;User ID=root;Password=xxx123.
If you're using a client SSL certificate to connect to your server, add this to the end of your connection string: ;SslCa=server-ca.pem;SslCert=client-cert.pem;SslKey=client-key.pem.
You must use MySqlConnection.
See this link for more information: https://cloud.google.com/dotnet/docs/getting-started/using-cloud-sql

C# Login Failed for User using Connection String localhost\SQLEXPRESS

I got error message when connecting my apps on client PC to the Database stored on Server PC(DESKTOP-F419755). I've tried using "localhost\SQLEXPRESS" and ".\SQLEXPRESS" but i got the same "Login Failed for user admin ..." message when trying to open connection. BUT, when i use "DESKTOP-F419755\SQLEXPRESS" for the Connection String it's works well on Client PC..
So how Client PC can connect to Server PC's Database without telling the Server PC Name.
My full Connection String was
"Data Source=localhost\SQLEXPRESS;Initial Catalog=data;User ID=admin;Password=adminPass"
note:
I can use either "localhost\SQLEXPRESS", ".\SQLEXPRESS", and "DESKTOP-F419755\SQLEXPRESS" on PC Server(Ofcourse).
So how Client PC can connect to Server PC's Database without telling
the Server PC Name
I am assuming you want to somehow mask the identity of the host in the configuration file for whatever reason. You can use the IP address directly in the connection string or add a host entry in the file: C:\Windows\System32\Drivers\etc\hosts
DESKTOP-F419755 serverhost
And use:
Data Source=serverhost\SQLEXPRESS;Initial Catalog=data;User
ID=admin;Password=adminPass
Is the configuration file exposed to users? What are you trying to accomplish exactly?
If your goal is to simply hide the machine name, this will accomplish albeit relatively half heatedly. If your primary concern is security you can pull the host name from somewhere inside the code and in the code generate the connection object therefore not needing the connection string stored in the config file.
This all depends on what you're trying to accomplish here, you could encrypt the information in the configuration file as well or store the host name somewhere else completely (registry, etc).
it's not possible to automate the connection string inside a client server location. however you can use another ways to store connection information to change without reinstalling the application.
Use a text file in a location with connection string. ensure that information are encrypted for security purposes.
Hope you got the answer.

SSH Access using Renci.SSH to MySQL Server

Trying to access a MySQL server using the Renci host SSH library.
I got it working by following the info Creating a forwarded port within an SSH tunnel
Specifically this line got my local port sucessfully set up such that it could be bound:
ForwardedPortLocal port = new ForwardedPortLocal("localhost", 3306, "localhost", 3306));
This is fine, but as I understand it the SSH client is binding to 3306 to receive data back from the server. This is a problem if the user has MySQL already installed as it will be using this port so my service cannot. Of course the service can be stopped but this is not a very friendly process.
I was expecting to be able to pass a High - Ephemeral - Port to listen on for the duration of my connection.
I got a bit confused on which parameter I should pass, having originally thought the second port would be the local port I need to bind to. After extensive experimentation on port configs I am at a loss as to how to handle this.
In addition I tried various overloads but none of the 3 other overloads seemed to produce what I wanted.
Any tips?
Thanks,
Andy
Ok I've resolved this now.
The solution is to modify the MySQL connector string so it uses a Ephemeral port. Picked one at random.
server=localhost; uid=;pwd=; database=; port=14324
Then modify the ForwardedLocalPort to bind to this port.
ForwardedPortLocal port = new ForwardedPortLocal("localhost", 14324, "localhost", 3306);
So we're forwarding the connection to localhost 14324 to localhost 3306 on the remote server.
Next challenge how to ensure that the port I use isn't already bound!!
So to do this use the overload that does not require a port number i.e.
ForwardedPortLocal("localhost", "localhost", 3306)
This will allocate an available Ephemeral port to your process which can be found using:
port.Start();
var portNumber = port.BoundPort;
This can then be added to your MySQL connection string.

Can't connect to local database while using connection string?

Here's my connection string
Server=XXX.XXX.XXX.XXX\SQLExpress;Database=inspection;User Id=sa;Password=xxx;
I'm getting an error that it couldn't connect, but when I use connection string like this
Server=.\SQLExpress;Database=inspection;User Id=sa;Password=xxx;
it connects successfully, I don't know whats problem (the Ip is correct)
If IP address is correct and you have firewall open and other stuff to be able to connect to this IP address, just try using it as is (i.e. without \SQLExpress part), so entServer=XXX.XXX.XXX.XXX;
You may not have enabled the TCP/IP protocol in the SQL Server Configuration Manager, which I believe needs to be enabled for connections that aren't localhost (i.e. .) to succeed.

mySQL Exception: Unable to connect to any of the specified MySQL hosts. through C#

strProvider = "Data Source=184.67.33.33;Database=abcd;User ID=abcd;Password=12345678"
is not working and
strProvider = "Data Source=184.67.33.33;Initial Catalog=abcd;User ID=abcd;Password=12345678"
is also not working.
it gives error at objmycon.Open()
I am using above string as my connection String and it gives mySQL Exception
I am not able to find any thing wrong with this.But still gives error
what could be wrong?
There could be some reasons for that issue.
Check your hosts file. (Go to Run menu and past+enter %systemroot%\system32\drivers\etc\. Open Notepad.exe in Administrator mode and edit hosts file.)
It should have
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost ::1 localhost
Very probably that you are using some Port to connect to MySQL. So you have to include Port number into connection string.
https://www.connectionstrings.com/mysql/
So it should like
Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;
Usually Port is 3306 so be careful what you are input like a MySQL Port number.

Categories