Along with the SQL Server, Database, Username and Password, don’t forget to include the Application Name in your connection string. It’s an optional parameter, but it can be a lifesaver. Data Source=myServer; Initial Catalog=myDB; User Id=myUsername; Password=myPassword; Application Name=myApp; Consider this example: There are multiple .NET applications running on a single web server. Each application [...]
We traced a performance bottleneck to a single function recently. Interestingly enough, this function has been in existence (running in a production environment in all of its glory) for roughly 4 years now. Only now that we are required to execute the offending piece of code approximately 10 million times within a short four hour [...]
Continue reading about Poor Performance with DateTime.Parse()
Exception handling is extremely important, isn’t it? When it comes to testing, troubleshooting and maintenance it is paramount. Exception handling is definitely highlighted on every developers list of application technical requirements. So, why don’t all applications have proper exception handling? I have a few ideas. The first and most likely reason is most developers (no [...]
Strings are immutable. In other words, a string can not be changed once assigned. When you append a string to an existing string, the .NET framework actually creates a new string containing the original string and the appended string. This is a resource-hungry and time-consuming process. The alternative to appending strings, is the StringBuilder class [...]
Continue reading about Improve String Management with StringBuilder
Assume we have a datarow field, name, which evaluates to null. What is the result of the following two cases? CASE A string name = Convert.ToString(dr["name"]); CASE B string name = dr["name"].ToString(); In the first case, Convert.ToString() will evaluate to null. In the second case, however, .ToString() will throw an exception. And it makes sense, [...]
Do you know how to short-circuit operators? In C#, And (&) and Or (|) operators evaluate both boolean expressions in the statement. However, the && operator only evaluates the first Boolean if false and the || operator only evaluates the first Boolean if true. This technique prevents the execution of the second expression if unnecessary [...]