SqlDateTimeOverFlow error [closed] - c#

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

Related

Getting data format error suddenly [closed]

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.

figuring out whether submissions were made on time or late [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
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.
Closed 9 years ago.
Improve this question
I have a set of requirements which I can't yet decide the best way to implement.
I have a table in the database for submissions, including the date a submission was made (Submission.Name, Submission.Date).
Each year, we want the user to make 2 submissions, one by April 1, and one by December 1
The requirements indicate that we show the user a notification on the home page, which can be one of three:
- submission completed for current period (green)
- submission pending by end of current period (blue)
- submission outstanding from previous period (red)
There is one additional rule which is that if a submission is overdue by more than 3 months, then
we should display the submission pending notification (blue) for the upcoming deadline instead of the red one.
The problem is when trying to determine if a submission that is in the first 3 months of the current period should be counted towards the current period or if it was just a late submission for the period before (which would have been overdue).
Checking previous periods for whether or not they were overdue might also require checking their previous
period ...etc. making it more complicated than I hoped.
The options so far look like either to query the table using EntityFramework to calculate the state, or to implement this logic in code, however, both options appear non-trivial so far.
Can anyone see a better approach to this kind of problem? Or does anyone have any Linq tricks to do this in one shot?
Edit: we want 2 submissions per year, but the user is free to make more than 1 submission per period, and hence why it's difficult trying to interpret how the submissions correlate back to overdue periods
Thanks in advance
Can't you just add a new field to your database, "LastSubmissionPeriod" and set it to
April 1, or December 1 so you know which period has been filled?

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.

Automated letter generation [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 4 years ago.
Improve this question
I work for a doctor and am looking for a solution to speed up his process of composing medical reports. Most of the text in the medical reports are redundant and should be able to be generated by a selection process
What I would like is to present him with a form with various options, checkboxes and the selections he makes will drive the generation of the report and create a word document that he can then fine tune or just save/print/whatever.
For instance he will be prompted with:
Age: ______
Gender : () Male, () Female
Length of Condition : () Week () Month () Year
Pain involving: [] Neck, [] Shoulder, [] Chest, [] Hip, [] Leg, etc....
This subset of the form would generate the following sentence:
"This is a 38 year old woman with a month history of pain in the leg"
I'd like the process to be data driven (as much as possible), so changes to the selection choices don't require reprogramming.
I would suspect that he is not the first person to ask for a system like this. So my first question is has anybody come across any existing software that we can purchase that would meet our needs?
In the event that no pre-packaged software is out there, I'd like some input as to general design strategies. What kind of data structure would you use to store the choices? How do I interface with word to create the document?
If I were to write this myself my language of choice would be C#.
EDIT:
A number of suggestion where made assuming that I'm looking for a Medical records package.
I don't think that is a solution to the problem I'm addressing.
The doctor is simply looking for a tool to automate his report writing. His reports are usually submitted as part of a workmans comp or no-fault case. They are for external consumption, and not usually not referred back to internally after the fact.
ANOTHER POINT:
The functionality I'm looking for isn't specific to the medical community. I'm looking for a tool where a given checkbox/radio button generates a specific sentence, and the mapping is configured by the user. Sort of a form letter on steriods.
Yes, there is definitely software out there that does this. You're looking for medical records software. The specifics of the software really depend on where the doctor is located, however. Because your profile indicates a New York location, I assume that you're in the United States. In that case, I know of exactly one offering in that domain. Perhaps they will or won't fit your needs (I've never worked with it myself), but NexTech certainly has a commercial product offering in that general market segment.
If you choose to build your own (which is always a possibility), be aware of the fact that there are legal requirements that surround such software. Once again, I'm not aware of specifics, but you may need to talk with the owner of the practice to ensure that your software doesn't violate any relevant privacy laws.
We automate creation of sales tax returns using open source PDF libraries. We're on Java, but here are some options for PDF generation on .Net.
In our case we work with a specific form template that the states provide and fill in amounts programaticly. It sounds like you're looking to accomplish something very similar.
You may want to have a look at medical, an electronic health record module for Open ERP. There are also a variety of commercial packages out there; e-MDs, for example, provides this specific feature.
I know Epic is a big player in this area, but they may be out of your price range.
I can think of these options:
XMLFO
Mail-Merge with MS Word
With the risk of being shot, but: That sounds like something that Microsoft Access was created for. You can easily generate the Form and Report. If you really need it as a Word Document (as opposed to simply using Access' Report function) you can link Word Documents to Access databases.
Just an idea.
I think you can just set this up in Word using fields. And the Doctor would just tab from field to field.

Looking for a tool to quickly test C# format strings [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I am constantly forgetting what the special little codes are for formatting .NET strings. Either through ToString() or using String.Format(). Alignment, padding, month vs. minute (month is uppercase M?), abbreviation vs. full word, etc. I can never remember.
I have the same problem with regexes, but luckily there's Expresso to help me out. It's awesome.
Is there a tool like Expresso for experimenting with formatted strings on standard types like DateTime and float and so on?
PowerShell works great for testing format strings. From PowerShell you can load your assembly and work with the objects and methods you want to test. You could also just create a string on the command line and test out different formatting options.
You can use the static method from the string class:
$teststring = 'Currency - {0:c}. And a date - {1:ddd d MMM}. And a plain string - {2}'
[string]::Format($teststring, 160.45, Get-Date, 'Test String')
Or PowerShell has a built in format operator
$teststring = 'Currency - {0:c}. And a date - {1:ddd d MMM}. And a plain string - {2}'
$teststring -f 160.45, Get-Date, 'Test String'
I just found this:
http://rextester.com/
Simply paste in your format string, and run the code.
It would also be simple enough to create a windows or console project that does exactly that.
Snippet Compiler is a great tool in general for quick small app testing. Instead of cluttering your Visual Studio with a million ConsoleApplication79 projects, just use this. I have it and use it constantly.
LinqPad is a great tool that handles this sort of thing brilliantly, even though it's tangential to its primary function (of troubleshooting Linq syntax).
Just enter the expression with the language selector set to "C# Expression" (or "VB.net Expression") and the database set to "None." For example:
String.Format("{0:d}-{1:d}", new DateTime(2012, 1, 6), null)
When you press Run, you'll get the result:
1/6/2012-
http://www.sellsbrothers.com/tools/#FormatDesigner
You could use the Snippy plugin for Reflector to run little code snippets.
Looks like the link is dead - just use LinqPad!
Just another simple utility, avaliable on MSDN: http://go.microsoft.com/fwlink/?LinkId=209564, description is:
an application that enables you to apply format strings to either numeric or date and time values and displays the result string.
But you need to compile it by yourself.

Categories