|
File this under, it worked fine yesterday.
<br />
Uri uri = new Uri("http://ftp.nhc.noaa.gov/atcf/aid_public/");<br />
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);<br />
request.Timeout = 1;<br />
HttpWebResponse response = (HttpWebResponse)request.GetResponse();<br />
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:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://ftp.nhc.noaa.gov/atcf/aid_public/");
request.Proxy = new System.Net.WebProxy(new Uri("my proxy server"));
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.
|
|
|
|
|
In a C# 2010 windows application, I am using the following to connect to a sql server 2008 r2 database.
The app.configuration file looks like the following:
<connectionStrings>
<add name="DEVConnectionString" connectionString="Data Source=dev2008;Initial Catalog=DEV;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
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?
|
|
|
|
|
|
Setup a username and password as a security login in your sql database managemnet engine and then add that user as a security user in your specific database.
Then add the user id and password to your connection string
Everyone using your app will access the db as the same user though.
|
|
|
|
|
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.
|
|
|
|
|
Shameel wrote: 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 a client application.
A server uses a different idiom.
|
|
|
|
|
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:
base(ConfigurationManager.ConnectionStrings["DEVConnectionString"].ConnectionString, mappingSource)
The app.configuration file looks like the following:
<connectionStrings>
<add name="DEVConnectionString" connectionString="Data Source=dev2008;Initial Catalog=DEV;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
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?
|
|
|
|
|
Don't try to edit *.designer.cs files as they are built and rebuilt by Visual Studio. If you want to access information in this way then you need to add the actual code into your main program.
|
|
|
|
|
I've just started learning C# yesterday, and I'm really confused with the reference system.
Can anyone please help explain to me what would happen here:
class Population{
public void DuplicatePopulation(Population thatPop){
x=thatPop.x;
}
public int x;
};
class GA{
public GA(){
InitPop=new Population();
CrossOverPop=new Population();
}
public Population FindPopID(int ID){
switch(ID){
case 1:return InitalPop;break;
case 2:return CrossOverPop;break;
default:break;
}
return InitialPop;
}
public void DuplicatePopulation(int FromID,int ToID){
Population FROM,TO;
FROM=FindPopID(FromID);
TO=FindPopID(ToID);
TO.DuplicatePopulation(FROM);
}
Population InitialPop,CrossOverPop;
};
class MainClass{
public void main(string[] args){
GA GeneticAl=new GA();
GeneticAl.DuplicatePopulation(1,2);
};
What I'm trying to do is duplicate population Init to Population CO. With this code, will the value of CrossOverPop.x == InitPop.x
Am I already passing by reference? or did i need to use the ref keyword?
|
|
|
|
|
All objects are inherently reference types i.e. they are passed around by reference.
So you don't need the ref key to pass them around.
|
|
|
|
|
The ref keyword has a special meaning when applied to reference types. When ref is applied to a reference type, you can actually make the variable point to a different object altogether. Passing without the ref keyword (the default) will only allow you to change the state of the object, you cannot make it point to a different object.
|
|
|
|
|
I'm making a GUI for a device. The connection goes across a bluetooth USB device.
Part of the process is to connect to the device.
The user clicks a button to make that connection.
When I encounter an error with the Serial Port, such as...
Semaphore TimeOut Expired
What do I tell the user to do ?
|
|
|
|
|
It depends on you design your application and how you managed your device classes. You can display understandable and friendly message to the user because most of the end users are No-wise operator. If you try to display technical errors in your message this will confuse them so a friendly message and if possible what to do next.
for eg: in this case you can show "Failed to connect to the device. Please try again" you can use the same message for any error that related to the connection and write the actual error in your log file so that field engineer or programmer can check the real problem from the log files.
Jibesh V P
|
|
|
|
|
We are creating a Software's extension dll. Here we will be using the Software's base dll which will be there in Software's Installed Location. But the extension dll will be installed inside a subfolder(Extensions) of the Software's Installed Location. In code i have added the Software's base dll reference and developed the code. Now what happens is the Software's base dll is copied inside the subfolder(Extensions) also which is not accepted. I should only take the Software's base dll from Software's Installed Location.
As the Software's Installed Location can be anything, how can i add dynamic reference to the Software's base dll. Please help.
|
|
|
|
|
Can you clarify with examples, where the various components of your application, are located. Also add the exact error messages you see.
e.g.
Development configuration (working)
===================================
App.exe
BaseDll.dll
ExtensionDll.dll
Deployment configuration (not working?)
======================================
App.exe
Extensions\BaseDll.dll
Extensions\ExtensionDll.dll
System.IO.FileNotFoundException: Could not load file or assembly 'BaseDll...........
I assume that whatever you had on the development machine works correctly. If the same relative paths are used in the deployed application does it still work?
|
|
|
|
|
Question as written is hard to understand.
Presumably you have a delivery that looks like the following
<root dir>\MyApp
App.exe
Base.dll
.\Extension\
Extended.dll
And you are loading Extended dll dynamically.
In that case Extended dll should be built using Base.dll.
There are two possibilities there.
1. You have already referred to something in App.exe which is in Base.dll. And thus Base.dll will already be loaded into the process (AppDomain) space
2. You have not referred to Base.dll. In that case the .Net load process will attempt to search for Base.dll. Presuming it is not in GAC then it will search in the App.exe directory and thus it will find it. And load it.
The above presumes you haven't messed with anything including setting up your own AppDomains.
|
|
|
|
|
Hi,
Now I have two questions here.
1.
I am using the graphics object to create a customized report from a database. To ensure WYSIWIG, I use the same functions in the paint event of the panel with the printPage event of a PrintDocument after passing the necessary event arguments.
So far there is no trouble. Printing and previewing works just the way I want.
(NB - Did not use the printPreviewControl as I felt it was way slower than a panel. Don't know if I am right.)
So, Am I going the right way to create a WYSIWIG compliant application?
2.
I want to save the created report into a XML format. I used the XMLWriter class, and was almost succesful in saving the report. I was ready to pat myself in the back and call it a day when it occured that I knew no way to serialize a Brush object. All I want to store is just the brush color.
How can I get the color of a brush object? Because I don't see any properties exposed. Any workarounds?
modified 30-Jan-13 7:49am.
|
|
|
|
|
Here is an advanced print preview dialog/control[^]. That may help.
As for the brush, figure out the type (likely a solid brush), cast it to that type, and serialize the properties you want.
e.g. (for a solid brush)
if(brush is SolidBrush)
{
SolidBrush sb = (SolidBrush)brush;
}
else if(brush is LinearGradientBrush)
{
}
Bob Dole The internet is a great way to get on the net.
2.0.82.7292 SP6a
|
|
|
|
|
Thanks a lot.
Casting the brush object was exactly what I needed. So simple.
And yeah, it was a SolidBrush.
Will have to study the PrintPreviewControl article a bit though.
Thanks again.
|
|
|
|
|
hi,
i need help to check the avaialbility of username from database. i am developing this website in a .net 3 tier framework. i already search for coides through google but all the codes are in 2 tier based. please help..............
|
|
|
|
|
We can't give you any specifics, because you don't give us any specifics.
But basically, you want to run a query on the database which is along the lines of:
SELECT COUNT(userName) FROM myTable WHERE userName='DoesThisExist' If it returns a non-zero value, then the username exists.
(By preference, make this a parametrized query, or you leave your database open to SQL Injection attack which can damage or destroy it)
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
The number of tiers doesn't matter.
|
|
|
|
|
Don't get so hung up on "3 tier" and stuff like that.
You have a very specific problem you are trying to solve so just focus on that alone.
What you need to do is run a query against your database to check if a value exists. That's it.
public bool UserNameExists( string username )
{
}
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Hi,
I had been working on C, C++, VC++ technologies for many years. I want to start learning C# .Net. I have little knowledge about C#.Net. I want to know from where to start.
And also what is the difference between C#, .Net, ASP.Net, ADO.Net etc etc ..
Any good books OR Tutorials to start from.
Any suggestion is welcomed.
Regards,
Mbatra
|
|
|
|