Getting data format error suddenly [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I look after a website which has news/blog section. As usual, admin can create/edit articles. It's been running fine for years but suddenly last week, I became to get an error saying "Input string was not in a correct format." when creating/editing articles. And I also get error notification email from the system as below;
Message: Error converting data type varchar to datetime.
The entry page has date fields but I use the same format I've been using and nothing has changed since the last time I created/edited articles successfully. The same files and code in the server. It suddenly started not to let me create/edit anything. Even it won't let me save articles without changing anything of the article.
It's running on ASP.Net(C#), MS SQL Server and IIS. As nothing has changed, I have no idea where to start but can this be happened?? And what would be the cause?
I don't know what exactly the culture setting was in the Windows Server but I don't see any incorrect setting. Current correct Region, Date and Time are there. No one has accessed to the server between the dates something went wrong. The SQL server uses the different setting from the server ones but it has been like this.
The website has some sections and the news/blog section gets the error but the other section, which also uses dates, don't get an error. Obviously these different sections uses the different files. So I think the server/SQL settings are OK. But as I mentioned, the files haven't changed at all.
Any other possibilities?? Thanks for your help.

Try to check if anyone has changed the culture settings on the server (on which your MS SQL Server is running). Control Panel, Region and Language.
DateTime parsing can depend on those settings if it uses the current culture on the machine.
Assumption 1:
Your asp.net application may unnecessary convert DateTime.ToString() when constructing the sql insert/update command.
Assumption 2:
It gets the string as it is and uses the session login default language and format (see SET LANGUAGE / SET FORMAT in SQL). Check if the default language/format has changed in your sql.

Related

Unrecognized database format In MS Access due to multiple locks functioning on the database file at the same time [duplicate]

This question already has answers here:
Recent rash of Microsoft Access database files in an inconsistent state
(2 answers)
Closed 2 years ago.
Hello EveryoneI have created a c# application with MS-Access database. But when I run it on network where multiple clients access the database at same time, following error occurred some times.Unrecognized database format I researched this topic a lot and found that this issue is happening due to multiple locks functioning on the database file at the same time.How can I overcome this. Please suggest.
Edit: When I try to open the database it shows some type of corruption and displays the following message Microsoft Access has detected that this database is in an inconsistent state, and will attempt to recover the database
Most likely you have been hit by the well-known lease bug being around for years. A good summarise can be found at Daniel's blog:
Access – Bug – Database is in an Unrecognized Format
The current status is, unfortunately, quo.

Programmatically identify PHP and ASP include dependencies [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to automate the cleanup of legacy/heritage code and I can identify current resources in use from IIS logs but server side pages like .ASP and .PHP have include chains which I would like to be able to identify via code (C#)
In order to narrow the question down as it was too broad ...
OS - Windows 10
Web Server - IIS
Preferred language - C#
Example - any IIS served website
I have code that reads IIS log files where I have identified all static served resources including the initial .ASP or .PHP pages.
I required some accompanying C# code to also detail any .ASP or .PHP included files that were processed on the server and therefore do not appear in the IIS logs.
As it happens I have found the solution and provided an answer below.
I hope this is enough detail to take this off 'On Hold'
Many thanks to #Progrock for pointing me to checking last accessed time for files in target folder. This is what I had to do.
Ensure capturing last accessed time is being set by Windows (see Directory.GetFiles keeping the last access time)
Process.Start("fsutil", "behavior set disablelastaccess 0").WaitForExit();
Also need to restart IIS to stop any cached in memory files
Process.Start("IISRESET").WaitForExit();
A refresh on FileInfo needs to be performed to ensure you get the correct last accessed time (see How can System.IO.FileSystemInfo.Refresh be used).
This resulted in the following code ...
var start = DateTime.UtcNow;
Process.Start("fsutil", "behavior set disablelastaccess 0").WaitForExit();
Process.Start("IISRESET").WaitForExit();
//do work that will access folder. i.e. access IIS web pages
var files = Directory.GetFiles(iisPath, "*.*", SearchOption.AllDirectories).ToList();
files = files.Where(x =>
{
var fileInfo = new FileInfo(x);
fileInfo.Refresh();
return fileInfo.LastAccessTimeUtc >= start;
}).ToList();
I can use this list of files to identify all .ASP and .PHP and any other files that were accessed via the IIS server on page requests.

SqlDateTimeOverFlow error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
ERRORI want to insert employee information in a table.There is a field name called as DateHired. Eventhough we have inserted the correct date ,its showing us the error saying Error - SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.What should I do now and what should I check for?
The most obvious issue, and I'm going to make an assumption here that dates are getting pushed down as a string. If I'm wrong, the rest of this may not apply to you but it might help someone else :-)
Make sure you aren't getting US and rest-of-world formats mixed up. For example 12/31/9999 is invalid in UK locale as it should be 31/12/9999. The former will give an overflow/out-of-range error (as there aren't 31 months).
If you need to push dates through as a string, the safest way is to use ISO format, i.e.: yyyy-mm-ddThh:mm:ss, for example: 2015-12-17T08:30:00. That 'T' that separates date from time is important. Without it, local locale rules kick in again.
A second safe way, especially if we're talking US vs. UK is to name the month, i.e.', "17 Dec 2015". This won't work if we're looking at US/UK vs. French, but it's okay for anglocentric apps.
Finally, make sure your app is connecting to the SQL database using a login with the right language. Execute DBCC USEROPTIONS as the user your application connects as - this will tell you the language and dateformat that user is using. You can change this through SSMS (Security -> Logins -> [find user] -> Properties -> Default language).
Some people might recommend using SET DATEFORMAT to work around this - but this comes with a danger when used liberally, especially within stored procedures: SET DATEFORMAT forces an execution plan to be recompiled at each execution (as documented in Microsoft's whitepaper Plan Caching in SQL Server 2008 - scroll down to "Factors that affect plan re-use"), and thus has an adverse impact on performance

Basic way to Enumerate a File List From a directory [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hi all am working with Directories and Files Counting Software..
Here, When I get or search Files from C:\ or D:\ it throws UnAuthorizedAccessException
I want to Enumerate Files Ignoring the file/Directory which is Inaccessible
How to ?? C# Visual Studio 2008 Exactly .NET Framework 3.5 only.
My code
var files = FastDirectoryEnumerator.EnumerateFiles(path, "*.reg.zip",
SearchOption.AllDirectories)
.GroupBy(f => f.Name).Select(g => g.First());
Here Am Taking files which ends with .reg.zip
I want to search it on my Whole Computer.. But the Exception..
VS 2008 Default User.. I Tried app.manifest with
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
but even though Exception.. while Searching in SystemVolumeInformation Directory..
I will start by saying this is not the best advice. However, it is a place to start.
My answer is two fold:
Firstly, I think you have prematurely optimised by using the FastDirectoryEnumerator before understanding the filing system level security issues you will face with your project. As such, if time permits, I would recommend a simpler solution as recommended in the post linked to by #phillip in the comments (UnauthorizedAccessException while getting files). For a remotely modern machine 120k files shouldn't be a problem.
Secondly, looking at the speed stats of the FastDirectoryEnumerator I can see the appeal of using it. Digging into the code a little, I can see that it doesn't protect you in any way from permissions exceptions when used as you have done. It is essentially procedural code wrapped inside an IEnumerable MoveNext method. The MoveNext method itself, has been made recursive for sub-directory processing.
I am not able to test this next bit, so you will have to experiment. If you want to hack around with the FastDirectoryEnumerator the first thing you might want to try is a try catch block around the creation of the new FileData object.
public FileData Current
{
get { return new FileData(m_path, m_win_find_data); }
}
If that doesn't work, you would have to work through the GetNext() method to trap the exception in the right place. You might need to go as far as implementing a NullObject pattern for FileData.
I hope that helps in some way.

Difficulty of switching from HTML only e-mail to Text only e-mail in .net C#? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am working with a consulting group on a program which currently uses a .net C# script to send e-mails in HTML format at regular intervals.
The e-mail itself aside from being in HTML format although the content is text with some tags and contains less then a page of text.
I would like the consultant to change this to text format replacing the tags with line feed/carriage returns. I have been told that this is a four hour job but that seems excessive to me.
When I look online at a page such as this http://www.mattvanandel.com/771/c-sending-an-email/ it would seem the change could be completed in less than 4 hours including recompiling the .net code into a DLL, testing and uploading the code to a server.
Not all developers are created equal, but assuming that the .Net developer is experienced enough to warrant a $250 per hour salary does this seem reasonable? If it is something less than 4 hours (i.e. more like 4 min) can someone tell me what might have to be done to make the modification. From what I can see its likely 2 lines of code that need to be modified (i.e. the body string and the IsBodyHtml statement). What else may I be missing?
Dependant upon what kind testing would be required to verify that the system is stable after the change, then perhaps 4 hours may or may not be excessive.
For a simple looking change in a tightly coupled system may have massive implications and risk. On the other hand in a loosely coupled system, the risk should be minimal.
So the question is, why 4 hours. If it was me. I'd request a breakdown of what the 4 hours represents. You are after all the customer and if you need a cost breakdown I'd suggest you're within your purview to request it.
However I'd suggest that you ask in a non confrontational way (i.e. don't jump in with all guns blazing) as the there may well be serious implications that the developer knows about but you don't. Maybe just ask for a simple - 'what is involved in implementing this change'.
And don't feel you have to accept the first answer given, you should if you are dissatified, request further clarification from the developer.
It all depends on how the code is written - and on that we can only speculate currently. It may be that they use a really complex 3rd party tool - in which case it might take four hours.
However, if it is done using System.Net.Mail then it could be as simple as setting the IsBodyHtmlproperty on a MailMessage to true, which is a four-second job.
Changing that 'IsBodyHtml' property would make it send text, but you would also need to modify the text to insert the line feeds - on static text this is not totally difficult, but you need to consider when a line feed is proper (what in the html has "block" layout and what is simple in-line styled). Also you do not mention if the text is dynamic or static which adds complications if it IS dynamicly generated.
Time you pay for, but also knowlege. I get someone else to fix things on my car, not because I can't, but because they are better and have the tools I might not have.
Just from a time spent perspective:
Get knowlege/use knowlege already present
Estimate time to communicate with you
Design the change
Code the change
Deploy the change
Test the change/functional test
Solicit feedback on the change/acceptance test (from you?)
There is only one property "IsBodyHtml" of MailMessage Class in .net to switch between Html/Text mail message type.
So you can check yourself, how big is the job excepting removing html tags and pumblishing the updated dll on server.
The mechanics of switching the code itself is as simple as you say above, replacing the HTML body string with the new string and changing the IsBodyHtml property. (Assuming the code uses the built in .NET Framework mailing components).
Remember though, that text based emails will remove all formatting, so you won't be able to have font colours, images, hyperlinks or anything else in the content except as plain text.
If you really want to cut the estimate down, get someone internal to edit the text and all the developer will have to do is switch 2 lines of code and then test/deploy.
I can't comment on the time required to test/deploy as that's entirely dependent on your system.

Categories