Månad: augusti 2009


Running FxCop on your assemblys is a good practice to keep your code clean and efficient. FxCop not only finds code that break “best practice” rules it also suggest´s how to correct them.

Some tips:

Properties should not return arrays

"Properties that return arrays are prone to code inefficiencies.
Consider using a collection or making this a method.
See the design guidelines for more information."

Specify format provider

"If an overload exists that takes an IFormatProvider
argument, it should always be called in favor of an
overload that does not. Some methods in the runtime
convert a value to or from a string representation
and take a string parameter that contains one or more
characters, called format specifiers, which indicate
how the value is to be converted. If the meaning of
the format specifier varies by culture, a formatting
object supplies the actual characters used in the string
representation. In scenarios where sorting and comparison
behavior should never change between cultures, specify
CultureInfo.InvariantCulture, otherwise, specify CultureInfo.CurrentCulture."

LastRefresh = Convert.ToInt64(marketFields[10], CultureInfo.InvariantCulture)

Download FxCop : http://www.microsoft.com/downloads/details.aspx?familyid=3389F7E4-0E55-4A4D-BC74-4AEABB17997B&displaylang=en


Truncate log on SQL 2008

Some times old tricks just dies, thats what happend with "BACKUP LOG WITH TRUNCATE_ONLY"
When you run that on a SQL 2008 server you will read: "truncate_only’ is not a recognized BACKUP option"
It´s gone deprecated because of misuse (what?), anywhay this the new style of doing the same thing wich is to clear the logfile.
USE dbname;
— Truncate the log by changing the database recovery model to SIMPLE.
— Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (2, 1);  — here 2 is the file ID for trasaction log file,you can also mention the log file name (dbname_log)
— Reset the database recovery model.

MS SQL 2008 Express a good start (pay when you really need it)

Express is the name of Microsofts “free” tools, to met the competition with the open source alternatives. I realy like SQL 2008 Express it is basically the full (and very expensive) version with som limitiations, wich are:

  • CPUs: Only 1 CPU. If a system has more than 1 SQL Express 2008 will still run but limit itself to 1 CPU.
  • RAM: 1 GB. More RAM can exist, but again SQL Express 2008 will only make use of a maximum 1 GB.
  • Database Size: 4 GB. This limitation provides for the storage of a considerable amount of data while protecting the domain of the higher-end SQL Server versions.
  • Many solution could live with this limitations it´s saves a lot of license money, and when the day comes there is no problem to change to MS SQL Server 2008, just install it and restore a backup file (it´s no differance between the database files).

    Enum ToString not obsolete (thank god)

    I have wondered why intellisense in Visual Studio marks the ToString method on a Enum type as obsolete. Should we not use it? I personallyl thinks that ToString is much easier then Enum.GetName method. I found this on MSDN, the Empty ToString() is not obsolete and could safely be used it won´t dissapear in the future (should be strange since object class has it and every datatype is derived from object). Why the strange behaviour in Visual Studio then, well it´s the overloaded methods ToString(IFormatProvider) and ToString(String, IFormatProvider) that are obsolte and therefore not recomended to use.