14 May 2013
Sometimes you will have the problem that you execute a long, time consuming query, e.g. in a stored procedure.
In our case we’ve got a maintanance plan that executes a stored procedure to generate statistics everey day.
But for this we will the following error on execution: “The query has been canceled because the estimated cost of this query (%d) exceeds the configured threshold of %d. Contact the system administrator.” (http://msdn.microsoft.com/en-us/library/aa337374.aspx)
You can fix this by setting the cost limit to a higher value or zero ...
14 May 2013
When you do calculations in your database, you sometimes have to deal with null and 0 (zero) values. This can lead to Divide-By-Zero errors or null-results. To prevent them we can use ISNULL and/or NULLIF.
Lets start with ISNULL. This simple fellow just needs two parameters. First the value to check and second the resulting value if the first is null.
This little snippet replaces salary with 1 if it is null.
NULLIF on the other hand does the opposite. If the first parameter has the same value as the ...
20 Apr 2013
When you want to use an image as brush, you have to decide where to put it. Best and easiest way is to include it as resource to your project.
Simply add to picture to your project (maybe in an subfolder called images) and change “build action” to resource, if its not already set.
To use this image just declare an ImageBrush with the image path and name.
Here i use the image w1.png in the subfolder Images in my project.
Use an absolute path to use an image outside ...
15 Apr 2013
In a previous post I wrote about debugging another application with mdbg. In this context I started to build an application that is able to log exceptions in other applications. But in some cases you can’t be sure that the monitored application is always running. So whats about e.g. small apps started by task scheduler? In this case you have to know when it’s started and when it’s ended – you will need the name of the application for this. The problematic aspect for this solution is that ...
12 Apr 2013
With the abstract class Type you can get alot of information about anything in C#. But although there are alot of Is… properties, there is no IsStatic.
If you want to know if a class is static you have to use IsAbstract and IsSealed. When both are true then you
have a static class.
To quote Microsoft:
“Do declare static classes as sealed and abstract, and add a private instance constructor, if your programming language does not have built-in support for static classes.”
A abstract class and a static ...
10 Apr 2013
Today I will show up how we could build an application that is able to can debug another. Since a while I got a problem to control an obsolete program that is productive for a while in the company I work, because it is regulary crashing and we have to know when this happens to react. For this reason I will build an application with the help of mdbg to notify when some problem with the problem occurs. First we have to download the mdbg sample from Microsoft. ...
9 Apr 2013
Sometimes it is necessary to find out which tables are consuming the most space in your database. especially when you run your database for a couple of years.
In our case we’ve got an ERP database which holds orders, position, customers, machine controls, print data, … So we need to find table that are predestined for archivating.
With this snippet you are able to find then. Hope that will help you.
1 Apr 2013
It is good practice to use enums to choose which part of the code should be executed, but sometimes you’ll get a string and have to convert it to an enum.
Here is, how you can do it.
First, declare a custom enum or use a given one.
And then use the Enum.Parse command. This command uses 2 parameters. First the type of the enum and second the string of the enum-value.
To get a string from an enum, just call ToString
15 Mar 2013
In .Net 4.0 Microsoft indroduces a new universal cache. For quite some time caches were already present in ASP.Net, but could (should) not be used in C# or VB.Net. With the new package System.Runtime.Caching there is now an easy way to implement a cache in any program, like a WebService or WPF-Application. As you will see, the caching package can manage all the object you want to cache, including different timeouts and proper memory usage.
To test the cache, create a new Project (WPF, Console, WCF or what ever ...
12 Mar 2013
Modern applications use animations to create nice effects and shorten waiting times. In a pie-chart its also used to show the difference between values or for presentations.
To create such an effect we’ll again reuse the Pie-Class i created earlier and add the shadow effect to it.
With WPF its very easy to generate different animations with a little bit ...