This week, I noticed my EC2-hosted website(.NET) would get this error about 50% of the time when trying to connect to my RDS database instance(SQL Server Express, Medium):
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Nothing has changed on either my EC2 instance or RDS instance(SQL Server Express). The error location was random and sometimes a simple page refresh would fix it.
After messing around and experimenting for quite a while, I found that the error went away when I switched my connection string from this(connecting via hostname):
<add key="strConn" value="Server=xyz.grtrtgrt.us-east-2.rds.amazonaws.com;Database=myDB;User Id=dbUser;password=dbPassword;Trusted_Connection=False;pooling=false;" />
to this(connecting via IP):
<add key="strConn" value="Data Source=1.2.3.4, 1433;Network Library=DBMSSOCN;Initial Catalog=myDB;User Id=dbUser;password=dbPassword;Trusted_Connection=false;pooling=false;"/>
I know we should be using the hostname to connect to an RDS, but I can't figure out why it would suddenly start throwing errors like that.
Any thoughts or ideas?
Thanks!
Related
I am running Metabase on Google Cloud Run and am trying to connect to a MySQL database instance (which also resides in Google Cloud SQL, in the same project).
NB. This is not Metabase's application database, but rather connecting a database to perform analysis on the data as per https://www.metabase.com/docs/latest/setting-up-metabase.html
When I run Metabase locally, I can connect fine using the Public IP (once my IP was whitelisted)
I cannot connect via Metabase on Cloud Run.
I have added the database to Cloud SQL connections within Cloud Run (per: https://cloud.google.com/sql/docs/mysql/connect-run)
The database I'm trying to connect to is a Read Replica (if that makes any difference)
When I 'allow all' on the Cloud SQL instance using 0.0.0.0/0 I am able to connect using the Public IP. Once I remove this rule I cannot connect.
I understand Cloud Run does not yet support Cloud SQL Private IPs
For connecting to the database I am constrained to using Metabase's web interface:
Within this interface I have tried:
Setting Host to the public IP
Setting the Additional JDBC connection string options to cloudSqlInstance=<INSTANCE_CONNECTION_NAME>&socketFactory=com.google.cloud.sql.mysql.SocketFactory as per https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory (with <INSTANCE_CONNECTION_NAME> replaced with the real name)
When I set this the error is: Could not connect to address=(host=<HOST>)(port=3306)(type=master) : Socket fail to connect to host:<HOST>, port:3306. Socket factory failed to initialized with option "socketFactory" set to "com.google.cloud.sql.mysql.SocketFactory" (I have redacted the real <HOST> value)
Thoughts:
From what I now understand, when I set socketFactory in Additional JDBC connection string options the host is ignored.
I can only assume I have not properly formatted or configured the Additional JDBC connection string options field
Any help would be greatly appreciated.
You cannot connect to CloudSQL thorugh any TCP connections as it is stated in the documentation:
Cloud Run (fully managed) does not support connecting to the Cloud SQL instance using TCP. Your code should not try to access the instance using an IP address such as 127.0.0.1 or 172.17.0.1.
You can connect to the CloudSQL instance, using the instance connection name using a code similar to this:
// The configuration object specifies behaviors for the connection pool.
HikariConfig config = new HikariConfig();
// Configure which instance and what database user to connect with.
config.setJdbcUrl(String.format("jdbc:mysql:///%s", DB_NAME));
config.setUsername(DB_USER); // e.g. "root", "postgres"
config.setPassword(DB_PASS); // e.g. "my-password"
// For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections.
// See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.mysql.SocketFactory");
config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_CONNECTION_NAME);
config.addDataSourceProperty("useSSL", "false");
// ... Specify additional connection properties here.
// ...
// Initialize the connection pool using the configuration object.
DataSource pool = new HikariDataSource(config);
[1]: https://cloud.google.com/sql/docs/mysql/connect-run
If you are concerned about the security of the connection you can always choose to connect to the CloudSQL proxy, using the JDBC socket factory. Please note that in this situation your JDBC URL should look like this :
jdbc:mysql:///<DATABASE_NAME>?cloudSqlInstance=<INSTANCE_CONNECTION_NAME>&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false&user=<MYSQL_USER_NAME>&password=<MYSQL_USER_PASSWORD>
Try to connect using the full URL and review it a few times. I've see this identical error when people did a little mistake in the JDBC Url, like an extra semicolon, colon etc..
You can't use Cloud SQL private IP with Cloud Run, it's not yet compliant, you can forgot this way. Read replica will change nothing, you can also save money and delete it!
First, allow you Cloud SQL database to be reached by 0.0.0.0/0 network. Like this, you can validate that your Cloud Run container work correctly with a database open to internet.
Then, delete this configuration and retry to follow this page for connecting your MySQL instance to Cloud Run as you did. In your application, you also have to add a dependency (maven or gradle) for getting the socket factory jar.
It should work. Share more code or configuration for being able to help you more!
2 years later, and I think perhaps conditions have changed. I was able to do this on Google App Engine, using the beta_settings configuration option in the app.yaml definition file.
For example
beta_settings:
cloud_sql_instances:
- <Project><Zone><Metabase_backend_postgresql_instance>=tcp:5432
- <Same Project><Same Zone><Some MySql cloud instance>=tcp:3306
When adding the database connection in the Metabase UI, the IP address needs to be set to 127.17.0.1 per Google documentation on the flex environment.
I'm using AWS to host my Chef server, and I've connected to it from my workstation using Knife. However, after shutting down and turning the server on, the Public DNS changed, and I'm unable to reconnect to the server, resulting in this message:
ERROR: Error connecting to https://*.compute-1.amazonaws.com/organizations/*/cookbooks?num_versions=all
Is there any way to change the address of the Chef server on the workstation without making the workstation think it's connecting to an entirely new server?
You need to reconfigure the Chef Server, possibly updating it's config file first to ensure the right hostname is in the right places. After that, make sure you update the chef_server_url in the knife.rb or client.rb of every machine.
I've been running an instance EC2 through Laravel forge for about 2000 hours and this morning got this error while trying to reach it:
SQLSTATE[08006] [7] could not connect to server: Connection refused Is
the server running on host "172...***" and accepting TCP/IP
connections on port 5432?
After SSHing into the server I've getting a similar error when trying to run a command. I've dug through AWS but don't see any errors being throw. I double checked the ip address for the instance to make sure the IP hadn't changed for any reason. Of course I'm a little behind on my backups for the application so I'm hoping someone might have some ideas why else I can do to try and access this data. I haven't made any changes to the app in about 10 days, but found the error while I was pushing an update. I have six other instances of the same app that weren't affected (thankfully) but makes me even more confused with the cause of the issue.
In case anyone comes across a similar issue, here's what had happened. I had an error running in the background which had filled up the EC2 harddrive's log. Since the default Larvel/Forge image has a DB running within in the EC2 instance, once it ran out of room everything stopped working. I was able to SSH in and delete the log though, and everything started working again.
To prevent the issue from happening again I then created an amazon RDS and used that rather than the EC2 instance. It's about three or four times the price of just an EC2 instance, but still not that much and the confidence I now have in the system is well worth it.
This might seem like a duplicate question but it is not. I tried to go through similar questions but I couldn't find a fix for my problem. Here is my problem:
I need to set up an ftp connection on company servers.
I can easily connect to ftp server from fileZilla on my PC but when I try it over one of the server machines to the file server all I see is the following:
Response: fzSftp started
Command: open "*****#***.***.***.**" **
Error: Connection timed out
Error: Could not connect to server
Status: Waiting to retry...
Status: Connecting to ***.***.***.**...
Response: fzSftp started
Command: open "*****#***.***.***.**" **
Error: Connection timed out
Error: Could not connect to server
I googled the "Connection timed out"
error and I realized that the first place to check is firewall or router setting. these are outsourced to another company and they say that the issue is solved and it should work fine. I don't know where to look at.
I've had lots of issues with Filezilla. You may try another software first to see if Filezilla itself is the issue.
If you're on Windows, I highly suggest the open source project WinSCP (https://winscp.net/eng/download.php). For Mac, Cyberduck (https://cyberduck.io/?l=en) is solid (and free), though you may prefer Transmit.
I was having this problem after upgrading Filezilla. I downgraded it to a previous version and it worked like charm. I came across this ticket thread and it was absolutely helpful : Filezilla Support Ticket
Check your security group rules. You need a security group rule that allows inbound traffic from your public IP address(Google: What is my ip?) on the proper port.
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
In the navigation pane, choose Instances, and then select your instance.
In the Description tab, next to Security groups, choose view rules to display the list of rules that are in effect.
For Linux instances: Verify that there is a rule that allows traffic from your computer(public ip) to port 22 (SSH).
For Windows instances: Verify that there is a rule that allows traffic from your computer(public ip) to port 3389 (RDP).
Also take a look at here and here for more details
I need to set up an ftp connection on company servers. I can easily connect to ftp server from fileZilla on my PC but when I try it over one of the server machines to the file server all I see is the following:
<failure to connect code>
Please note that public IP and internel IPs will be a different address; such as 123.456.675.574 for the public but internal to the server network it will be something more like 192.168.10.574 .
This is why you can easily connect from your PC because it uses the public IP address but from the internal IP network of the company servers that address will not be valid, and the internal one would need to be used instead.
Try this, 200 is just an example, just increase it and try.
Edit --> Settings --> Connection --> Timeout in seconds = 200
I'm trying to setup a connection to FTP to transfer a file. Unfortunately, because of the environment the tools I have available to me are limited.
I'm receiving the following error:
An error occurred while establishing an FTP connection.
Error: Connection refused: connect.
Does this mean that I can reach the FTP server but the credentials are incorrect? Does it mean that I can't reach the server at all? Or is there no way to tell?
Update: I changed the IP address I was using to some other random number, so it's almost certainly because I can't connect. I wish there was a way to tell the difference between connectivity and authorization issues.
A "Connection Refused" error means that either the server you're trying to connect to isn't running an FTP server, or there's a firewall in your way that's preventing the connection.
An "User Authentication failed" error would usually occur if your credentials are bad.
FYI, for plain old FTP connections, the cfftp.errorCode may give you more information, once your are able to establish a connection. The errorCode will point to the response in the IETF FTP protocol standard , like "425", which would mean "Can't open data connection.".
Could be either one of those cases. Do you have a standalone FTP client to test with? Does it work from another machine?
hey check if your directory attribute is begining with a "/" character. this used to work through cf8 but stopped working for me in cf9 (specifically 9.0.1);
also try the following and see if this helps:
<cfftp connection="mycon" server="myserver.com" action="open" username = "anonymous" password = "anonymous" />
<cfdump var="#mycon#" label="">
<cfftp connection="mycon" action="getcurrentdir" result="result"/>
<cfdump var="#result#" label="">
you may find that its the listdir that is giving you the problem, not the connection.
You can check your ability to connect to the FTP server using Telnet at the command prompt(On windows, Go to Start > Run > type cmd).
telnet my-domain-name.com 21
you can try at non default port as you wish. That will let you know if your machine can reach the FTP server, and you can try logging on to check your credentials.
Here's a good post: Understanding FTP using raw FTP commands and telnet