Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am developing a program which is connecting to SQL Server which I obtained a static/public IP for it let say it as: 141.52.88.212 on port 2458.

The program is working fine and connected to the server without any issue from everywhere in internet.

However, I installed the program inside my company PC which have intranet only. To connect to internet I have to use proxy let say it as: 215.221.60.4 on port 80 (this is not the real IP).

Now the problem is that the program is not working because of proxy setting obviously.

How can I add the proxy setting in my WPF application?

I am using the following connection string:

C#
connectionString="Server=141.52.88.212\\SQLSERVER,2458;MultipleActiveResultSets=True;Async=true;User ID=UserTest;Encrypt=FALSE;TrustServerCertificate=FALSE;initial catalog=SQLT_TEST;Application Name=SSMA for Access;Pooling=False;PASSWORD=Pass;"


This connection is working fine on any computer not inside the company.

I tried to insert proxy setting as below:

in App.config:
XML
<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true"/>
  </system.net>


In App.xaml.cs:
C#
private void Application_Startup(object sender, StartupEventArgs e)
{
IWebProxy webProxy = new WebProxy("215.221.60.4", 80);
webProxy.Credentials = CredentialCache.DefaultCredentials;
WebRequest.DefaultWebProxy = webProxy;
}


But no luck.

Please help me.

Thanks.

UPDATE:

I discussed with IT and they said that the proxy deals with all protocols.

However, I tried to change my Port to (80) because the previous port was rejected by firewall and now the problem is that when we check using Wireshark program, my program is trying to connect to the server directly without going throw Proxy.

Is there a way to check if my sqlconnection is actually having proxy setting correctly in WPF?

Also, is there a way to change SQL protocol to HTTP rather than TCP using any other way such as HTTP-Tunneling for example?
Posted
Updated 4-May-14 0:06am
v2
Comments
Pheonyx 1-May-14 7:34am    
Why are you trying to go out to the internet just to come back in?
Why not have an "internal" and "External" connection string and connect to the appropriate one.

You could have a setting called.. "ServerAddress" which stores the IP and when you load your base connection string you replace the "Server" value with the correct IP and choose the one based on whether the current machine has an IP that matches the internal IP pattern ?
ZurdoDev 1-May-14 8:55am    
You just need to change the connection string to be whatever they can connect to.
[no name] 4-May-14 6:13am    
When you changed to port 80 then your program started to try and connect to a webserver. The simplest answer, to me anyway, is that your proxy does not know anything about SQL Server ports.

1 solution

The sql server communication protocol is not http.

Probably the internal proxy of your company only deals with http protocol, so it is not possible to connect to an external sql server via http proxy.

Talk to your system administrator, and ask if it is possible to create an exception in the firewall in order to make a connection to the outside.


JAFC
 
Share this answer
 
Comments
Maciej Los 1-May-14 14:51pm    
Sounds reasonable, +5!
José Amílcar Casimiro 2-May-14 3:22am    
;)
fahood12 2-May-14 13:27pm    
Thanks for your reply

I will check with IT on Sunday
fahood12 4-May-14 6:04am    
I discussed with IT and they said that the proxy deals with all protocols.

However, I tried to change the my Port to (80) because the previous port was rejected by firewall and now the problem is that when we check using Wireshark program, my program is trying to connect to the server directly without going throw Proxy.

Is there a way to check if my sqlconnection is actually having proxy setting correctly in WPF?

Also, is there a way to change SQL protocol to HTTP rather than TCP using any other way such as HTTP-Tunneling for example?
José Amílcar Casimiro 4-May-14 6:51am    
I found this article: "Connect to SQL Server Through a Proxy Server".
http://msdn.microsoft.com/en-us/library/ms179448.aspx
Maybe this can help u.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900