Monday, April 30, 2012

SQL Server: String or binary data would be truncated.

Msg 8152, Level x, State x, Line x String or binary data would be truncated.

What does this mean?
This is the equivalent of SQL Server telling you that you are trying to fit too much into a container and if you were to do so then something would be left out. As a result, by default SQL Server won't allow this so that is why you are seeing the error.

Solution 1
If you don't want to lose any of your data, then you must increase the size of your column.

Solution 2
If you don't care if data is truncated and just want the message to go away then you must use "SET ANSI_WARNINGS OFF" with each execution of your sql statements with respect to .Net programming. Unfortunately there is no way to turn off this warning at a server or database level, it has to be set per connection. So if you are opening and closing connections with each execution then you must use that statement before executing your statement. I searched long and hard to turn this off at a database level, supposedly there is a way to do it, but all of the things I have tried did nothing.


Saturday, April 28, 2012

SATA Drive Dynamic Invalid Disk


If you are getting a funky error while mounting a SATA drive to the effect of: "Dynamic Disk Invalid"

Then check out this link:
http://windows7forums.com/windows-7-support/3906-dynamic-disk-invalid.html

Using a hex editor you need to go to sector 0 of your problem disk, row 1C0, column 02 and change the value "42" to "07". Save and reboot your machine. That will make your SATA volume become a basic volume. I would only recommend doing this if you plan on just pulling data from the drive and wiping it afterwards or if you just don't care what happens to the drive afterwards.

The software you need to do this is called HxD you can get it here.

Make sure that when you are editing your disk via the Hex Editor that you don't open the drive as Read Only, otherwise as expected you won't be able to change jack.


Please keep in mind that if you follow these instructions you do so at your own risk. I can't guarantee anything. I can however say, it worked for me.

Hope this helps anyone who was looking for it.

Tuesday, April 24, 2012

Visio 2010 Activation Error 0x80072EFD

This is not a terribly useful post, it is more of a piece of advice. If you have the option to activate this software by phone, then do so. I searched and searched via Google to solve this problem and I couldn't. I spent 10 minutes on the phone doing the number reading and writing exercise and that activated my software with no problem.

Not everyone is so lucky, if you are using a trial version it seems that phone activation is not an option.

Monday, April 23, 2012

DataGridView Loses Formatting and Columns After Setting DataSource a Second Time

Problem
This was particularly annoying. If you have a DataGridView you are working with, you have setup the DataGridView through the designer and you have set the DataSource once. Then you set the DataSource a second time because the data has changed - all of a sudden you lose all of your formatting and the column names are all wrong.

Solution
As stupid as this sounds, set the DataGridView's AutoGenerateColumns property to False!
DataGridView.AutoGenerateColumns = false; //C#
DataGridView.AutoGenerateColumns = False; 'VB.Net

There - goddamn annoying vague problem solved!

More Banter
This makes sense for this to happen, but it is still annoying. Basically what is happening is that the list of objects are being loaded into the DataGridView and overriding the existing formatting. Something similar happens in ASP.Net which is that all the predefined columns are loaded in addition to the columns from the list of objects. Windows Forms just happens to only respect the list of objects and won't show your predefined columns... that part is silly and not so obvious.

Thursday, April 19, 2012

Windows Form Designer File Hell: Object reference not set to an instance of an object

I spent 2 hours trying to figure out why a form I was working on was telling me that there was something wrong with a control in the designer and that is why the form wouldn't render. I was getting the dreaded "Object reference not set to an instance of an object" error. It wasn't believable because all of the code in the designer was fine. I have seen this error countless times and each time it is for something that will give you a head palm moment. You might not want to believe this, but you - the programmer - are definitely at fault when this happens. It turns out that code in a file that wasn't even part of the windows form was attempting to use an object before it was instantiated. Thus head palm moment and it was my co-workers fault because I didn't write the code :D.

I am going to try to generalize the steps to take to fix the problem.

  1. Don't get angry, calm down, go get some coffee or watch a YouTube video for about 5 minutes. Avoid getting pissed off when dealing with these frustrating issues because it isn't going to help.
  2. Avoid editing the Designer File directly, chances are that is NOT where the problem is. If your problem is the Designer file then there is something really messed up and the only way to fix it really is to blow away the whole form and start from scratch, but only do that in a last resort scenario.
  3. If you can run your code then this is an indication that it probably isn't the form itself or the controls on the form. Your problem lies somewhere in the actual thicket of your code.
  4. You are looking for a place where an object is being used un-instantiated just like the error tells you. The bad news is that the compiler might not tell you exactly where this is happening.
  5. Time for you to start debugging your code. If you can walk your code that is a good sign, because at least it gives you a chance to find out where the problem is occurring.
  6. If you are getting an error like this one: "Exception has been thrown by the target of an invocation" then this means that an exception is being thrown by something that has been invoked such as a proxy call or an event. Those are harder to debug, but it all comes down to the same thing:
  7. You need to wrap the code that you suspect is throwing the exception in a try/catch block and inspect the exception.
  8. After capturing the exception look at the stack trace and find out who the culprit is.
  9. More often than not this will find you the un-initialized object.
If you cannot compile your project because you have a designer file that is broken then check this link out:

This is for the same reasons essentially. If you do not instantiate your public properties of custom controls then the designer file will initialize them to null for you. That is not very helpful when your form breaks what seems to be randomly. The designer is slow to act on somethings and usually won't happen until you do a rebuild or if some other major change occurs causing a rebuild (IE: adding a file, removing a file etc...).

Friday, April 13, 2012

Programmer Breakfast

I don't have a good time waking up in the morning. I am usually a zombie and I grunt to communicate until my vocal cords have warmed up enough to allow me to speak. I don't normally get a chance to eat any breakfast until I get to work. Here are three of my preferred morning breakfast foods that I prepare all in the same container... yep you guessed it - in my Mug.

Every programmer must have a Mug even if they don't drink coffee. Programmers who don't drink coffee are decaf programmers, and I hate decaf coffee it is terrible. There is something wrong with you all for not drinking coffee, but it is okay we can still be friends.

I have a mug, it is my most favorite mug in the whole wide world and I got it here. I love my mug because it displays how I feel and it helps me measure my breakfast.

Here are three things you can prepare in your mug:

  1. Instant Oatmeal - just add hot water
  2. Carnation Breakfast Envelopes - just add hot water
  3. Liquid Egg(white) Product - microwave 1 serving in your mug
I alternate between these three so I don't go completely crazy eating the same damn thing every day. It does get a little boring even with these three, but they are all convenient at work foods. The liquid egg product obviously needs to be refrigerated and for safe measure put your name on it.

I prepare everything in my mug: breakfast, then afternoon coffee, sometimes tea and sometimes cocoa.

Thursday, April 5, 2012

My.Request Equivalent in C#

The Gotcha
When moving VB.Net code to C# code that uses the My namespace such as "My.Request" the equivalent for you to use is "HttpContext.Current.Request". Pretty much you can assume that all of the properties exposed from "My" is actually something else, somewhere else. Good luck finding them and matching everything up properly, it is a pain in the ass.

This link should help: http://msdn.microsoft.com/en-us/library/ms172990(v=vs.80).aspx
On the left hand side it has a listing of all of the My.* stuff. If you click on them it will tell you what the actual underlying class is that is being used.

The Gripe
This took me a good 1-2 hours to figure out and I am little steamed about it. This yet one more reason why I don't like VB.Net, VB.Net is too friendly with some of its naming conventions and it will mask really important information such as the origins of a property.

I am converting a VB.Net Web Site over to a C# Web Application and I was having a bitch of a time figuring out what the hell "My" meant. There is no equivalent for "My" in C#, which in my opinion is preferable. I would rather use the full qualification vs. some arbitrary shortcut that is only good in one language.