Uri uri = new Uri("http://ftp.nhc.noaa.gov/atcf/aid_public/");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Timeout = 1;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Yesterday, this code works fine. Today it doesn't. From what I can tell I think the IP address on the server has changed. When I remove the timout and wait, I can see that an incorrect IP address is being used. However, I can browse to the URL so the DNS is correct on my system (even command line tools resolve to the correct IP) I have tried flush DNS although, to be honest, there is no reason that should work, and it didn't resolve the issue.
So, I am left assuming that somehow, the .NET framework is caching an IP address somewhere. Now, I could reset the machine or clear all of the .NET temporary files but that would leave me with a temporary solution. What I need/want is someway to force .NET, via code, to always resolve the DNS and to not use any cached DNS (Assuming this is the error)
Also, if you have any troubleshooting suggesting that are "in-code" let me know. Rebooting, etc, is not an option because this will eventually be production code so it needs to be robust, I can't hold the hands of the application.
This is a two part issue. The root cause is a proxy server but this was masked by the following scenario:
The code base is shared between a Windows Forms application and an ASP.NET application. When I went from Windows Forms to ASP.NET I got the error. However, when I went back to Windows Forms, I still got the error leading me to conclude that the issue was not caused by ASP.NET. If I am to speculate, the persistence of the issue has to do with a secret cache by .NET, I cheated and cleared the System.Net.ServicePointManager internal service point tables but that did not resolve the issue, rebooting did however. So now that I knew the code worked in Windows Forms but not ASP.NET and sometimes not back-and-forth I had more to go on.
It seems that ASP.NET, does not use the PROXY servers configured for the local machine. My particular workstation uses a proxy configuration file and not a direct proxy so I had to research the proxy. When I use HttpWebRequest under windows forms the proxy is automatically used but when I use the HttpWebRequest under ASP.NET the proxy is ignored. With this little tidbit:
Solves the issue. Overall this makes sense that it is a proxy issue, however, I would expect HttpWebRequest to behave in the same manner under both environments?
Last note, my above code will not work with an authenticated proxy, of course, but if anyone has a similar issue, good place to check.
Rant, why oh why, can't I get uniform consistent behavior and why must their be a myriad of "secret" configuration files that alter "consistent behavior" because, to be honest, I am certain the issue is not Windows Forms vs ASP.NET but secret (ok, not really secret) but numerous configuration files all conspiring to, by default, offer different behavior in the different environments.
The problem is once someone besides myself runs the application, it will not run correctly.
Thus I am assuming that the Integrated Security=True needs to be changed to a username and password that is setup for the
application to run.
Is my assumption correct? If not, would you be able to tell what I need to do so someone besides myself can run the application?
Your assumption is correct. Your windows domain must be added and given permission in SQL Server for Integrated Security to work. As a best practise, you should always create a dedicated database user specifically for your app and apply principle of least privileges to that user. For example, you would want your application to insert, update and delete rows from tables, but you wouldn't want you app to DROP tables or DROP the entire database itself. As a matter of fact, I have seen production applications using the built-in 'sa' account to access the database, which is really a security issue. Creating a separate user and streamlining its access also protects your database from vulnerabilities in your applications like SQL injection attacks.
In a C# 2010 windows application, I am getting the following error message:
"The connection property in the Application Settings file is missing or incorrect. The connection string from the .dbml file has been used in its place".
I am also getting the warning message: warning CS0618: 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete,
it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings".
What I am trying to do is obtain the connection string information from the app.configuration file instead from the app settings file.
To accomplish this goal I am chanigng the *designer.cs to use the following code to obtain the connection string information:
The app.configuration file looks like the following:
<add name="DEVConnectionString" connectionString="Data Source=dev2008;Initial Catalog=DEV;Integrated Security=True"
The above code works fine when I setup the code initially.
However once I reopen the soltuion file, I get the message listed above,
""The connection property in the Application Settings file is missing or incorrect.
The connection string from the .dbml file has been used in its place".
To solve this problem, I was trying to do the following steps:
1.Step 1: Right click on the .DBML file and select "Run Custom Tool".
2.Step 2: Set "Application setting = false" in the connecton properties of your DataContext.
3.Step 3: press "Save All".
The problem with the above solution is once I selected "Run Custom Tool", nothing happened. There was nothing for me to select.
Thus can you tell me and/or show me in code how to solve this problem?