Posted on December 8th, 2008%
Which one is correct?
ShutDown()
or
Shutdown()
I’m not quite sure. Seems many Windows API calls reference it as Shutdown. Not being convinced, I did a Google search, and found an article on The Old New Thing that summarizes why there is confusion.
Basically, it boils down to this:
shutdown = noun
shut down = verb
So, my method is called ShutDown, because methods should be action phrases (verbs). The enum value will be Shutdown, because that’s a noun (the state of something).
Who says all those grammar classes in grade school don’t apply . . .
→ Read More: ‘Shutdown’ or ‘Shut Down’?
Posted on December 8th, 2008%
The other day I started working on a WMI wrapper that would encapsulate workstation management functionality (starting and stopping services, querying workstations, etc.). Unit testing, as always, is important, but I inevitably came to one problem.
How do you unit test a method that reboots a workstation?
The answer: Run the unit test, and if your machine starts to shut down, that means it’s the end of the workday, and your test passed. (It was already 6PM on a Friday, so such behavior . . .
→ Read More: Unit testing a WMI reboot
Posted on December 3rd, 2008%
If you’re reading nvarchar(max) or ntext data from a SQL database using an output parameter with ADO.Net, you may find that the strings returned are one character in length, even though the field has more than one character of text.
This is happening because there is no Size property declared with your SqlParameter, which apparently tells ADO.Net to assume a size of 1. The solution, fortunately, is easy: specify a size of -1.
See the below examples which illustrate how to work around this ‘feature’.
// the following line doesn't specify a length, so the returned string will be one character long
SqlParameter badParam = new SqlParameter("@mynvarcharmax", SqlDbType.NVarChar);
badParam.Direction = ParameterDirection.Output;
// the following line resolves this by specifying a length of -1
SqlParameter goodParam = new SqlParameter("@mynvarcharmax", SqlDbType.NVarChar, -1);
goodParam.Direction = ParameterDirection.Output;
// if you are creating your SqlParameter by providing a parameter name and value,
// just specify the size after construction
SqlParameter goodParamWithValue = new SqlParameter("@mynvarcharmax", "my object value");
goodParamWithValue.Size = -1;
goodParamWithValue.Direction = ParameterDirection.Output;
// if using .Net 3.5, you can . . .
→ Read More: ADO.Net SqlParameter and missing text in the output value
Recent Comments