GCloud - Connecting App Engine Flex to Cloud SQL in other project - asp.net

I'm trying to connect my app engine flex service to the cloud sql database that is in a shared project.
I have added the app engine default and app engine flex user as SQL admin to the shared project.
Now I'm trying to connect the app engine container to the cloud sql instance with the following connection string:
"Server=cloudsql;Database=cliche;User Id=user;Password=password;"
However, the connection always fails with the given connection string.
[13:57:37 ERR] An error occurred using the connection to database 'cliche' on server 'cloudsql'.
[13:57:37 ERR] An exception occurred while iterating over the results of a query for context type 'IKL.Data.ApplicationDbContext'.
Microsoft.Data.SqlClient.SqlException (0x80131904): 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: TCP Provider, error: 40 - Could not open a connection to SQL Server)
As requested I provide the app.yaml here:
runtime: aspnetcore
env: flex
service: platform
manual_scaling:
instances: 1
resources:
cpu: 2
memory_gb: 1.5
disk_size_gb: 10
beta_settings:
cloud_sql_instances: shared-resources-291914:europe-west3:edutec-mssql=tcp:1433

I found your issue! Your connexion string "Server=cloudsql;Database=cliche;User Id=user;Password=password;" isn't correct.
Cloud SQL proxy open a tunnel. one side of the tunnel is the Cloud SQL instance, the other is your local instance. Therefore you have to connect on the local host
"Server=127.0.0.1;Database=cliche;User Id=user;Password=password;"

If you are using VPC Peering between your App Engine Flex project and your Cloud SQL project, then I must inform you that this is not possible to do yet, when you use an internal IP on your Cloud SQL, it will automatically use a VPC peering (different from the one you are probably using), and traffic between 3 VPC peerings is not posible.
You can use a VM in your Cloud SQL project to serve as a NAT server to route traffic onto your Cloud SQL there in order to workaround this, or you can use a Cloud VPN between your App Engine and Cloud SQL project, if possible please make sure that the NAT VM is in the same region as your Cloud SQL server or that the VPN on your SQL project is on the same region as your SQL server.
Also, please keep in mind that you would need to have the appropriate GCP firewall rules on all the involved GCP projects.

Related

Cannot connect dockerized ASP.NET Core app to dockerized SQL Server

I have just configured the project to connect to a dockerized SQL Server. add-migration and update-database commands via VS worked so I think the connection string is fine. I'm guessing it has something to do with the built app being in a container. I don't use docker-compose. I plan on running them separately.
The app successfully ran but it shows this error when performing actions with the database and shows this error:
SqlException: 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: TCP Provider, error: 40 - Could not open a connection to
SQL Server)
The documentations couldn't help me out. Other questions similar to this but none of the solutions worked such as the AllowRemoteConnections set enabled (already enabled by default).

Unable to connect to Azure hosted SQL Database from within Windows Docker container

I am unable to connect to my Azure hosted SQL database from within the Docker container, the application is an ASP.NET MVC on .NET 4.7 application running on a Windows hosted Docker container with IIS.
My connection string looks like this:
data source=tcp:[hostname],1433;initial catalog=
I believe this could be a DNS issue or something with the connection string, has anyone had this problem before? When I run the app locally or within Visual Studio w/IIS Express it works perfectly; when run from inside the container, it is refusing to connect to the Azure SQL database. It isn't a firewall or rules issue since I can connect from my host machine just fine, it's something to do with the docker container.
Exception is:
SqlException - 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: TCP Provider, error: 0 - This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server.)

Shiny - My Redshift Database Won't Connect Once Published

My Shiny application connects to my Redshift instance locally, but I get the following error when I try to run the application once I publish it to shinyapps.io
Warning: Error in connection_create: could not connect to server:
Connection timed out
Is the server running on host "redshift.bi.tmmp.io" (23.23.70.97)
and accepting TCP/IP connections on port 5439?
How would I allow connection to pass once published online?
A time-out normally indicates that the application could not connect to the server (as opposed to the server rejecting the connection).
You should start by checking the Security Group associated with the Redshift instance to confirm that it will accept incoming connections from the application.
The best configuration is:
A Security Group on your application instance (App-SG), which is associated with the application instance(s)
A Security Group on the Redshift instance (DB-SG) that permits inbound Redshift (port 5439) connections from App-SG, which is associated with the Redshift instance
That is, the Redshift security group refers to the application security group.

How to setup Azure web service with sql database

I wonder how can I connect my web role to existing SQL database ? Under settings tab in properties of web role I've tried to add new setting with connection string to my database, but when i try to Login (I'm using asp.net Identity, and using code first migrations I've successfully seeded DB), I get this error:
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: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
So what is correct way to connect my DB to web role ?
There was stupid problem with my connection string, I've solved it.
Take a look at the dashboard for your SQL Azure database. Click on the "Manage allowed IP addresses" link.
Make sure that the Windows Azure Services are set to YES under allowed services.
All The SQL Databases on Azure require a whitelist for IP ranges that can access them.

Why I am not able to connect to remote SQL Server from asp.net website whereas it is connecting from SQL Server Management Studio

Why I am not able to connect to remote server from asp.net website whereas it is connecting from SSMS
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)
I tried all the possible solution suggested in this link
I checked Followings as given in the above article, they are enabled/running
SQL Server is up and running.
TCP/IP enabled in SSCM
Opened port in Windows Firewall
Remote Connection enabled
SQL Server Browser Service running
I searched for sqlbrowser.exe but it is not found in the given directory.
Finally I switched off Windows Firewall but still it is not working.
UPDATE: we are connecting to sql server using a custom user created on sql server (not sa )
I have user account credential to Remote connect to server.
I tried to change LogOn to my credentials (administrator) . in Windows Services SQL Server (MSSQlServer) and SQL Server Agent (MSSQL Server) services.
Double check your connection string - are you connecting to a hostname that needs to be added to your Hosts file? For example "dev-sql1" but without a matching entry in dns or hosts file.
If you have created a custom user, can you check if logins are disabled for the user?
In SSMS, goto Security, right click user, Properties -> Status, Login - Enabled.
Hope this should fix it.
Three possibilities and they are not mutually exclusive.
Most hosting providers disable remote connections to SQL servers. Check with RackSpace if blocking port 1433
The SQL Server needs to be reconfigured to accept remote connections. See http://support.microsoft.com/kb/914277
You have to use a different connection string. See http://www.connectionstrings.com/sql-server and look for Connect via an IP address
I got the same issue but with mysql server. Rack space had two mysql server address. One for connecting from outside their local network and one for connecting from inside the network. you will have to use the address that is required to connect from inside the network.

Resources