Great Primer for Threading Basics in .Net

I stumbled across this article from one of my LinkedIn friends,  Threads in C#

It answered one of my questions about thread pooling in a very concise, easy to understand fashion.  It is a short article, but he then goes into the Task Parallel Library, something that I really enjoy.

If you are asking why should I care about this, I use the magic of Async/Await.  These are the fundamental technologies and techniques that they are built upon.

Keep in mind that not many people are experts in highly concurrent systems, I am not one of them either.  But hopefully by reading this article we will all be a little better in how we implement parallelism/concurrency.

Cheers!

Advertisement

SQL Server Performance Tuning For Developers

Chances are if you are reading this, you are a software developer.  Relax, I am one too, as well as a database administrator.  I spend a lot of time helping people to write code that is efficient or get the right results.  I want to share this post on SQL Database Tuning http://www.toptal.com/sql/sql-database-tuning-for-developers by Rodrigo Koch. It provides some really good advice, especially for beginners in the area.

Really hits the nail on the head though, keep it minimalistic. Only return what you need, it takes more time on the server and then the data has to go over the network.  He goes into some detail of how to troubleshoot slow queries and when to create indexes

 

A ClickOnce gotcha – FIPS algorithms

If you are using FIPS, your ClickOnce applications might not work. I ran into this bug running BookSmarts, an application I wrote. Turned FIPS on and started receiving errors.

The issue is that enabling FIPS makes the mechanism that verifies the validity of ClickOnce applications fail every time.

The article, a very long one, can be found here: https://support.microsoft.com/en-us/kb/811833

Just keep this in mind if you are trying to support someone who is the odd ball out.

Note: Enabling/Disabling FIPS in Windows is done through the registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy\Enabled (DWORD)

1 is on, 0 is off

When changing this setting, it’s necessary to reboot the computer.

DataGridView, FormattingException, DataError, and PreferredSize ~ Auto-Sizing Issue

Alright so I think I now have a good handle on this now. If you are using auto sizing for your columns, you might run into a formatting exception. The error you get says that you can handle the error in the DataError event.

If you start error handling within that event you might notice that you get a context of 5 which says it is either a Formatting or PreferredSize data error context. To quote MSDN:

A data error occurred when calculating the preferred size of a cell. This value indicates that the DataGridView failed to calculate the preferred width or height of a cell when programmatically resizing a column or row. This can occur if the cell failed to format its value.

Cancel the event by issuing the following e.Cancel = True after checking to make sure that the DataGridViewDataErrorEventArgs (e) has the context of 5 for PreferredSize

Visual Basic 2010 Object and List Initialization

I just found this out and I am really excited about it! The With & From are cooler than ever!

Check this out:

Module Module1
Private Class TestClass
Public Property Subject As String
Public Property Grade As String
Public Property Student As String
End Class
Sub Main()
Dim myTest As New TestClass With {.Grade = "A+", .Student = "Myself", .Subject = "Advanced Chromotography"}

Dim test As New System.Collections.Generic.List(Of TestClass) From {
myTest,
New TestClass With {.Subject = "Math", .Student = "John Bowman", .Grade = "B"}}

End Sub
End Module

The With and From are now part of the declaration statement, saving even more real estate on the screen.

Powershell Retrieving Remote System Time

Compare Local Date and Time to a Remote Computer

This is a rather interesting problem. I was doing a comparison between an audit table and a trace for SQL Server, which was proving to be dificult as I soon realized there was latency as well as the system date’s had an offset. So I turned to my good old friend, Powershell. Powershell has a very nice interface for coding against WMI, which I fully leveraged in this code snippet.

#Server name here. 
$ServerName = <Server Name Here>
#Retreive the localtime of the server. 
$remoteDate = Get-WmiObject -ComputerName $ServerName -Class win32_operatingsystem -Property LocalDateTime
#Converting a WMI time to a standard datetime format. 
$remoteDate = [System.Management.ManagementDateTimeConverter]::ToDateTime($remoteDate.LocalDateTime)

$localDate = Get-Date

#Displaying the difference. 
$remoteDate - $localDate

OracleConnection ~ Connection String Nightmare

I spent quite a bit of time today debugging an oracleconnection object. It would fail everytime the connection string property was set. This is what I would recieve in the error log:

Faulting module name: KERNELBASE.dll, version: 6.1.7601.17651, time stamp: 0x4e2111c0

Exception code: 0xe0434f4d

Fault offset: 0x0000d36f

I didn’t get to far Duck Duck Go’ing (or Googling) on this so I threw the assignment into an try catch block. I got an error  “Connection string is not well formed”. Connectionstrings.com had a great section on Oracle so I copied/pasted it into my code changing the pertinent data. Same issue.

After trying several things I discovered that the connection strings for Oracle cannot have a trailing semi-colon.

Data Source=IDWorks;User Id=IDWorks;Password=idw;

Data Source=IDWorks;User Id=IDWorks;Password=idw

Hope this saved you some time!

DirectoryOperationException – The object does not exist.

System.DirectoryService.Protocols Library

This was a very frustrating error. I was able to connect to LDAP through LDAPadmin but not through a program I was creating. “The object does not exist” error occurs, at least in my experience when the credentials you are passing to the server do not authenticate.

In this case I was getting nowhere. Resorting to Wireshark, filtering against port 389, which is the port for LDAP resulted in me seeing a backslash in the credentials being passed as well as the username coming after the organization, which is wrong for my environment.

The resolution was to set the domain to nothing in VB or null in C# in my Net.NetworkCredential object. At the same time moving the organization to the username property.

Dim credLDAP As New Net.NetworkCredential(“cn=username”,”password”, “o=domain”)
does not work, but this does:
Dim credLDAP As New Net.NetworkCredential(“cn=username,o=domain”,”password”, nothing)

Powershell – Remove Columns From Fixed Width Files

Here is something that works incredibly well.

This is a quick description enter the file names you wish to use. Powershell then reads in all the data and creates a new file by joining all the elements in the char array to a string. It then takes the row and ends it in a carriage return / line feed. Finally it saves the file.

$fileName = c:\file.txt
$newFileName = c:\newfile.txt
$newFile = “”
Get-Content -Path $filename | ForEach-Object{$newFile += [string]::Join(“”,$_[0..149] + $_[154..777]) + “`r`n”}
$newfile > $newFileName