I have a project that uses Entity Framework Model First
. The data source is in the internet, and I need it work using a network/web proxy for it. I had google it but I can't find any useful result, because all results are about EF's Entities Proxies
.
Some helpful code:
The connection string:
<add name="ConnectionName" connectionString="metadata=res://*/Latin.csdl|res://*/Latin.ssdl|res://*/Latin.msl;provider=System.Data.SqlClient;provider connection string="data source=mssqlserver.server.com;initial catalog=DatabaseName;user id=admin;password=adminPass;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
The usage:
static void Main(string[] args)
{
//set the proxy
var proxy = new WebProxy("109.32.24.24", 808);
proxy.Credentials = new NetworkCredential("", "");
WebRequest.DefaultWebProxy = proxy;
var db = new ContextName();
if (db.QNames.First().Name == "Testing")
{
Console.WriteLine("Success Connection!");
Console.ReadKey();
}
}
This raises a network connection error.
EDIT
The proxy that the network have is running over http protocol. I know that http is the protocol you normally use to browse the web with, you do not usually connect to databases with it
but it is the only available and this question is about it. You can use web proxies for several .net connections, even Web Services, and my question is about using it with EF, I could't make this working. One last solution could be to use a program like Proxifier
and redirect all computer's connections to the specified web proxy, but the idea is making it a bit more configurable.