30 April 2010

How to create custom configuration section

To create custom configuration section on a web.config or app.config file the attribute ConfigurationCollectionAttribute must be used.

In my example let us create a custom section named mails. It has the mails collection to send messages.


<configuration>
<configSections>
<section name="Mails" type="Samples.XProg.MailsSection, ConfigurationCollectionAttribute" />
</configSections>
<Mails>
<sendlist>
<clear />
<add name="mail1" mail="mail1@noip.com" />
<add name="mail2" mail="mail2@noip.com" />
</sendlist>
</Mails>
</configuration>


using System;
using System.Configuration;
 
namespace Samples.XProg
{
class TestMailConfigurationSection
{
static void Main(string[] args)
{
MailsSection mails = ConfigurationManager.GetSection("MailsSection") as MailsSection;
 
Console.WriteLine("Mails list:");
for (int i = 0; i < mails.SendList.Count; i++)
{
Console.WriteLine("Name={0} Mail{1}", mails.SendList[i].Name, mails.SendList[i].Mail);
}
 
Console.ReadLine();
}
}
 
public class MailsSection : ConfigurationSection
{
[ConfigurationProperty("sendlist", IsDefaultCollection = false)]
[ConfigurationCollection(typeof(SendListCollection), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")]
public SendListCollection SendList
{
get
{                    
return (SendListCollection)base["sendlist"];;
}
}
 
}
 
 
public class SendListCollection : ConfigurationElementCollection
{
public UrlsCollection()
{
}
 
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.AddRemoveClearMap;
}
}
 
protected override ConfigurationElement CreateNewElement()
{
return new UrlConfigElement();
}
 
protected override Object GetElementKey(ConfigurationElement element)
{
return ((UrlConfigElement)element).Name;
}
 
public MailElement this[int index]
{
get
{
return (MailElement)BaseGet(index);
}
set
{
if (BaseGet(index) != null)
{
BaseRemoveAt(index);
}
BaseAdd(index, value);
}
}
 
new public MailElement this[string Name]
{
get
{
return (MailElement)BaseGet(Name);
}
}
 
public int IndexOf(MailElement mail)
{
return BaseIndexOf(mail);
}
 
public void Add(MailElement mail)
{
BaseAdd(mail);
}
protected override void BaseAdd(ConfigurationElement element)
{
BaseAdd(element, false);
}
 
public void Remove(MailElement mail)
{
if (BaseIndexOf(mail) >= 0)
BaseRemove(mail.Name);
}
 
public void RemoveAt(int index)
{
BaseRemoveAt(index);
}
 
public void Remove(string name)
{
BaseRemove(name);
}
 
public void Clear()
{
BaseClear();
}
}
 
 
public class MailElement : ConfigurationElement
{
public MailElement(String name, String mail)
{
this.Name = name;
this.Mail = mail;
}
 
public MailElement ()
{
}
 
[ConfigurationProperty("name", IsRequired = true, IsKey = true)]
public string Name
{
get
{
return (string)this["name"];
}
set
{
this["name"] = value;
}
}
 
[ConfigurationProperty("mail", DefaultValue = "http://www.microsoft.com", IsRequired = true)]
public string Mail
{
get
{
return (string)this["mail"];
}
set
{
this["mail"] = value;
}
}
 
}
}

23 April 2010

Get only the date part of a DATETIME

To get only the date part of a DATETIME on an efficient manner use the following code:


CAST(FLOOR( CAST( GETDATE() AS FLOAT )) AS DATETIME)

15 April 2010

Fastest Storage for SQL Server please

A SQL Server database server with large data files, low main memory and slow data storage (disks) can compromise the performance of an application.
The solution is to add more main memory or get a fastest storage. If the data files are too large then the fastest storage is the only option.
There are solutions that really can do miracles...but at a price.
One of those solutions is the RamSan-440.
The main specifications are:

- 256GB or 512GB DDR RAM primary storage backed up by fast flash secondary storage
- Over 600,000 random I/Os per second
- 4500 MB/s random sustained external throughput
- Full array of hardware redundancy to ensure availability
- Exclusive Active Backup® software constantly backs up data without any performance degradation. Other SSDs only begin to backup data after power is lost.
- Patented IO2 (Instant-On Input Output) software allows data to be accessed during a recovery. Customers no longer have to wait for a restore to be completed before accessing their data.

With this hardware the problems are over...but when you talk to a CEO or an Administrator about the solution and the price, in most of the situations he doesn't mid to wait!!! :))

For more information press here.

You can also take a look at The Fastest Solid State Disks (SSDs)