Connect local SQL Server database from the containerized Asp.net Core Application - docker-container

I have a very simple "hello world" kind Asp.net Core API Application (swagger included) where I click one API Controller and it fetches the data from the database and returns as JSON. I have tested that working on my system through the debugger and it all good to go inside docker.
I have created a docker file (not docker compose) and build the image finally run the docker container and checked the application is indeed accessible. However, the API Controller which fetches the data from the database, that endpoint failed.
I have tried all possible options like
https://medium.com/#vedkoditkar/connect-to-local-ms-sql-server-from-docker-container-9d2b3d33e5e9
How do I connect the local SQL Server database for the ASP.NET Core application running inside either local Docker or Kubernetes?
I have the latest docker version (20.10.2, build 2291f61) which supports host.docker.internal and that does not work either.
I have tried after disabling the firewall, have used the IP Address with port 1433, have used host.docker.internal and everywhere It gives same error to connect to the database.
Well, I tried to same IP Address and connect locally through SQL Management Studio and confirmed that I am doing any mistake in typo for username, password or SQL server, and database.
I am having an asp.net core API application where the connection strings store under appsettings.json.
None of the suggested approaches is working. Any different option/ clue?

Try to run the container in with host network
docker run --network host myimagename myappcontainer
This way myappcontainer will be able to access the mssql running on your machine.

Related

Migrate .NET Core app from Google App Engine to Google Cloud Run - SQL connection issues

I have a .NET Core API currently running in App Engine and everything is working fine there. I am connecting to the database by following Google provided example, defining cloud sql instance in app.yaml:
beta_settings:
cloud_sql_instances: <sql connection name>
Along with env variables like DB_HOST: cloudsql and other credentials.
Note that I am using a custom runtime and provide the dockerfile myself.
While trying to deploy my app to Cloud Run, I've tried setting up the environment variables in the same way as I am providing them in my app.yaml file, as well as providing cloud sql connection name and adding it (note that I could not see the connection name I want, out of 4 existing SQL instances I could only see 2), the same one I use in my app.yaml. Deployment fails with an error:
Unhandled exception. 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: 35 - An internal
exception was caught)
I've tried following this post, but still nothing changed. Other attempts:
I've configured my SQL instance to have a private IP assigned and tried using it at DB_HOST field, still got the exception
Tried changing SQL connection name to other instances (appropriately changing environment variables), still got the exception
Created a VPC Connector and added it to my revision, still got the same error.
How can I fix this? What am I doing wrong?
If you are migrating an existing web application, see Migrating Your Service to Cloud Run.
Check if your app meets all the criteria for Cloud Run.
Checked this document about connecting to a Cloud SQL instance from a service running in Cloud Run. The steps to configure Cloud Run depend on the type of IP address you assigned to your Cloud SQL instance. You can also check about connection options.
You can follow this example about Google Cloud SQL with MySQL for Cloud Run.
It could be helpful to check this SO post about the correct Cloud SQL connection string syntax for dotnetcore app with Cloud Run.
Alright so I managed to make it work by following this quickstart guide, it's quite confusing really to have many different sources about Cloud Run connecting to SQL. Adding the environment variables mentioned in the guide solved the issue.

.NET SQL Server Connection by name and IP differs in behavior

Not sure if this is a StackOverflow question, but we hit this really strange problem with our ASP.NET 4 web app.
So, there is a typical connection string to SQL Server with Data Source specified in web.config.
SQL Server is run on VM on the same host as Web VM runs. They are in one network. If we specify connection using VM name, like "sql-server-vm", the web app works properly without any issues. But if we specify IP address of SQL Server VM instead, we start running into transient issues, like long server answers or timeouts.
Trying tracert the IP from the Web server VM shows the proper IP, so it's definitely the same machine and it is avaliable by name and IP. We are using ASP.NET Web API 2, ADO.NET, SQL Server 2014 SP3 in this project.
Is it possible that connection using ADO.NET does not properly work with IP address, but works with SQL Server Instance name? I cannot imagine a reason for this, but this is clearly what happens.

Laravel 5.3 update to remote apache server

I have an Ubuntu machine in Azure with my Laravel project and it works good. Today, I used Laravel Auth on my localhost environment and it works too. I save the data in a local database.
Now I need to update my Laravel project in Azure. It is just update the project or I need some configuration on virtual machine to work with the local database?
The only thing you should focus is you have an Ubuntu instalation, either it is on DigitalOcean, AWS or Azure, all are same.
Secondly, consider installing Laravel Homestead on your local machine. That will assure you that the server and local development have all the same components, so you can be pretty sure that if it works on your localhost, it will work in your server.
As for your question, please conpare the verion of the components on your system (local) and server. If both are same, everything would be fine.

What is the correct way to install Celery/Redis to run the tasks on another server?

The web server itself runs django. I would like the web server to delegate the actual tasks work to another server.
First, setup your redis server on the remote server. Change your django configuration to connect to this server.
When you deploy your app, I recommend using fabric to deploy to your web server and your worker server. It should handle the restart logic as well.

Are there any special deployment requirements for a REST Service to Azure?

I have written a REST service with windows azure using the WCF Rest Service Templates.
Locally everything runs fine. However when I deploy to Azure then all my requests return 500 Server Error.
Are there any special deployment requirements for a REST Service to Azure ?
I don't see anything in my project that points to local.
I left everything in the web.config set to defaults.
You should remote desktop into the Azure instance and check the Application Log. See this post on how to connect to the remote server instance. Most likely you are missing an assembly reference.