Asked by:
Connect ASPNET Core web application to a Sql Server database through a SOCKS proxy

Question
-
User-1484296732 posted
I have an ASPNET .Core application running on a pod in Kubernetes in AKS. The pod's network is an Azure's private network that is linked to my company's on-premise network via VPN. The web application at runtime connects to different SQL Server DB instances that reside both on the Azure's private network and on the company's on-premise network (I cannot move those on the Azure's network).
The problem that I have is that the web application can access the SQL Server instances that reside on the Azure private network but cannot reach the on-premise's ones. To solve the problems I was thinking to enable a Squid SOCKS proxy on the Azure network that would proxy all the connections to the SQL Servers in the company network. I used this same method to let the application connect to some HTTP services that reside on the company's network using a Squid HTTP proxy, and it's working.
The question is, how to configure the .net core application in order to let it use the SOCKS proxy when using the SqlConnection class? This is how currently I connect to the DBsusing SqlConnection conn = new SqlConnection(connectionString); conn.Open(); using (SqlCommand command = new SqlCommand(query, conn)) using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { results.Add(tupleHandler(reader)); } }
Thank you
Tuesday, October 27, 2020 3:37 PM
All replies
-
User1535942433 posted
Hi gvdm90,
I have an ASPNET .Core application running on a pod in Kubernetes in AKS. The pod's network is an Azure's private network that is linked to my company's on-premise network via VPN. The web application at runtime connects to different SQL Server DB instances that reside both on the Azure's private network and on the company's on-premise network (I cannot move those on the Azure's network).
The problem that I have is that the web application can access the SQL Server instances that reside on the Azure private network but cannot reach the on-premise's ones. To solve the problems I was thinking to enable a Squid SOCKS proxy on the Azure network that would proxy all the connections to the SQL Servers in the company network. I used this same method to let the application connect to some HTTP services that reside on the company's network using a Squid HTTP proxy, and it's working.
The question is, how to configure the .net core application in order to let it use the SOCKS proxy when using the SqlConnection class? This is how currently I connect to the DBsCould you tell us your project is Azure now?
Best regards,
Yijing Sun
Wednesday, October 28, 2020 5:15 AM -
User-1484296732 posted
Hi Yijing
I didn't catch your request. What should I provide you?
Wednesday, October 28, 2020 7:34 AM -
User1535942433 posted
Hi gvdm90,
I didn't catch your request. What should I provide you?What's the type of your project? Is it Azure?
Best regards,
Yijing Sun
Wednesday, October 28, 2020 8:20 AM -
User-1484296732 posted
It's a .net core aspnet project. I compile it in a Docker container and deploy it on my AKS cluster
Wednesday, October 28, 2020 8:31 AM -
User-1484296732 posted
So there is not way to connect to a SQL Server instance via SOCKS in .Net core? it may be a third party library or a different way to access the DB, but it cannot be possible that only I have this problem
Friday, October 30, 2020 7:40 AM