<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2027769947859867205</id><updated>2012-02-16T01:16:53.172-08:00</updated><title type='text'>Iroshan's Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>33</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-1607444492276132809</id><published>2010-07-15T17:21:00.000-07:00</published><updated>2010-07-15T17:22:53.857-07:00</updated><title type='text'>App.Config</title><content type='html'>&lt;?xml version="1.0" encoding="utf-8" ?&gt;&lt;br /&gt;&lt;configuration&gt;&lt;br /&gt;   &lt;appSettings&gt;&lt;br /&gt;      &lt;add key="Key0" value="0" /&gt;&lt;br /&gt;      &lt;add key="Key1" value="1" /&gt;&lt;br /&gt;      &lt;add key="Key2" value="2" /&gt;&lt;br /&gt;   &lt;/appSettings&gt;&lt;br /&gt;&lt;/configuration&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;sAttr = ConfigurationManager.AppSettings.Get("Key0");&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-1607444492276132809?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/1607444492276132809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=1607444492276132809' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1607444492276132809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1607444492276132809'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2010/07/appconfig.html' title='App.Config'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-1157379145302335916</id><published>2010-07-15T17:20:00.000-07:00</published><updated>2010-07-15T17:21:47.510-07:00</updated><title type='text'>DB Class</title><content type='html'>using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;&lt;br /&gt; public class DataManager&lt;br /&gt; {&lt;br /&gt;  public DataManager()&lt;br /&gt;  {&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static DataTable ExecuteQuery(string query)&lt;br /&gt;  {&lt;br /&gt;   string connectionString = System.Configuration.ConfigurationSettings.AppSettings["connectionString"];&lt;br /&gt;   SqlConnection connection = new SqlConnection(connectionString);&lt;br /&gt;   connection.Open();&lt;br /&gt;   &lt;br /&gt;   try&lt;br /&gt;   {&lt;br /&gt;    SqlDataAdapter adapter = new SqlDataAdapter(query, connection);&lt;br /&gt;    DataSet ds = new DataSet();&lt;br /&gt;    adapter.Fill(ds);&lt;br /&gt;&lt;br /&gt;    return ds.Tables[0];&lt;br /&gt;   }&lt;br /&gt;   finally&lt;br /&gt;   {&lt;br /&gt;    if ( connection.State == ConnectionState.Open )&lt;br /&gt;     connection.Close();&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  public static void ExecuteNonQuery(string query)&lt;br /&gt;  {&lt;br /&gt;   string connectionString = System.Configuration.ConfigurationSettings.AppSettings["connectionString"];&lt;br /&gt;   SqlConnection connection = new SqlConnection(connectionString);&lt;br /&gt;   connection.Open();&lt;br /&gt;   &lt;br /&gt;   try&lt;br /&gt;   {&lt;br /&gt;    SqlCommand cmd = new SqlCommand();&lt;br /&gt;    cmd = connection.CreateCommand();&lt;br /&gt;    cmd.CommandType = CommandType.Text;&lt;br /&gt;    cmd.CommandText = query;&lt;br /&gt;&lt;br /&gt;    cmd.ExecuteNonQuery();&lt;br /&gt;   }&lt;br /&gt;   finally&lt;br /&gt;   {&lt;br /&gt;    if ( connection.State == ConnectionState.Open )&lt;br /&gt;     connection.Close();&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public static object ExecuteScalar(string query)&lt;br /&gt;  {&lt;br /&gt;   string connectionString = System.Configuration.ConfigurationSettings.AppSettings["connectionString"];&lt;br /&gt;   SqlConnection connection = new SqlConnection(connectionString);&lt;br /&gt;   connection.Open();&lt;br /&gt;   &lt;br /&gt;   try&lt;br /&gt;   {&lt;br /&gt;    SqlCommand cmd = new SqlCommand();&lt;br /&gt;    cmd = connection.CreateCommand();&lt;br /&gt;    cmd.CommandType = CommandType.Text;&lt;br /&gt;    cmd.CommandText = query;&lt;br /&gt;&lt;br /&gt;    return cmd.ExecuteScalar();&lt;br /&gt;   }&lt;br /&gt;   finally&lt;br /&gt;   {&lt;br /&gt;    if ( connection.State == ConnectionState.Open )&lt;br /&gt;     connection.Close();&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-1157379145302335916?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/1157379145302335916/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=1157379145302335916' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1157379145302335916'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1157379145302335916'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2010/07/db-class.html' title='DB Class'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-3494015095580468041</id><published>2009-11-03T01:38:00.000-08:00</published><updated>2009-11-03T02:22:02.768-08:00</updated><title type='text'>Remove RowGUID columns</title><content type='html'>-- drop rowguid indexes&lt;br /&gt;select 'drop index ' + sysobjects.name + '.' + sysindexes.name from&lt;br /&gt;sysindexes&lt;br /&gt;inner join sysobjects&lt;br /&gt;on sysindexes.id = sysobjects.id&lt;br /&gt;where objectproperty(object_id(sysobjects.name),'IsMSShipped') = 0&lt;br /&gt;and sysindexes.indid &gt; 0 and sysindexes.indid &lt; 255 and (sysindexes.status &amp;&lt;br /&gt;64)=0&lt;br /&gt;and index_col(sysobjects.name, sysindexes.indid, 1) = 'rowguid'&lt;br /&gt;order by sysindexes.indid&lt;br /&gt;&lt;br /&gt;-- remove rowguid default constraints&lt;br /&gt;select 'alter table ' + b.name + ' drop constraint ' + QUOTENAME(a.name) from&lt;br /&gt;sysobjects a&lt;br /&gt;inner join syscolumns on syscolumns.id = a.parent_obj&lt;br /&gt;inner join sysobjects b on syscolumns.id = b.id&lt;br /&gt;where syscolumns.name = 'rowguid'&lt;br /&gt;and objectproperty(object_id(b.name),'IsMSShipped') = 0&lt;br /&gt;and a.xtype = 'D'&lt;br /&gt;&lt;br /&gt;-- remove rowguid columns&lt;br /&gt;select 'alter table ' + sysobjects.name + ' drop column '+QUOTENAME(syscolumns.name) from&lt;br /&gt;syscolumns&lt;br /&gt;inner join sysobjects on syscolumns.id = sysobjects.id&lt;br /&gt;where syscolumns.name = 'rowguid'&lt;br /&gt;and objectproperty(object_id(sysobjects.name),'IsMSShipped') = 0&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-3494015095580468041?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/3494015095580468041/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=3494015095580468041' title='21 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/3494015095580468041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/3494015095580468041'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/11/remove-rowguid-columns.html' title='Remove RowGUID columns'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>21</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-167308116841885905</id><published>2009-07-13T21:17:00.000-07:00</published><updated>2009-07-13T21:19:49.987-07:00</updated><title type='text'>Take database to sigle user mode</title><content type='html'>ALTER DATABASE TEST SET SINGLE_USER WITH ROLLBACK IMMEDIATE&lt;br /&gt;&lt;br /&gt;Take back in to multi user&lt;br /&gt;&lt;br /&gt;ALTER DATABASE TEST SET MULTI_USER&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-167308116841885905?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/167308116841885905/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=167308116841885905' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/167308116841885905'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/167308116841885905'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/07/take-database-to-sigle-user-mode.html' title='Take database to sigle user mode'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-190416191855491596</id><published>2009-06-09T22:35:00.000-07:00</published><updated>2009-06-09T22:38:10.380-07:00</updated><title type='text'>Walk-through of CLR Integration with SQL Server</title><content type='html'>One of the project requirements is writing all the stored procedures and user-defined functions in CLR integration. Although I don't intent to give you the overview of CLR integration in this article, it's not a bad idea to go over the benefits you get from using CLR integration. Stored procedures and user-defined functions/types/aggregates authored in managed code compiles into native code prior to execution, and you can achieve significant performance increases in scenarios where complex computations or business logics are involved. When you create these CLR objects, you can leverage various functions and services CLR provides for the program execution, such as JIT, thread handling, memory allocating, type conversion etc.&lt;br /&gt;&lt;br /&gt;The following step-by-step example will show you the common tasks performed in CLR integration projects.&lt;br /&gt;&lt;br /&gt;    * Enabling CLR integration in SQL Server&lt;br /&gt;    * Create a SQL Server Project in Visual Studio 2005/2008&lt;br /&gt;    * Create a managed stored procedure&lt;br /&gt;    * Deploy the CLR assembly using Visual Studio&lt;br /&gt;    * Execute CLR objects&lt;br /&gt;    * Deploy assemblies onto production environment&lt;br /&gt;&lt;br /&gt;The Northwind database will be used in the example I created. If you do not have the Northwind database, go ahead and download it here and restore it to your SQL Server 2005/2008 instance.&lt;br /&gt;&lt;br /&gt;Enabling CLR integration in SQL Server&lt;br /&gt;&lt;br /&gt;CLR integration is disabled by default in the SQL Server 2005/2008. To enable it, connect to the database to which you want to deploy the CLR assembly,  execute the SQL statements below and then restart the SQL server instance.&lt;br /&gt;&lt;br /&gt;EXEC sp_configure 'clr enabled', '1'&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;reconfigure&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Create a database project in Visual Studio 2005/2008&lt;br /&gt;&lt;br /&gt;Creating a CLR project in Visual Studio 2005/2008 is beyond simple. Go to File --&gt; New Project --&gt; Visual C#, and then select "SQL Server Project". Rename the project to NorthwindOrdersCLR.&lt;br /&gt;&lt;br /&gt;CreateProject&lt;br /&gt;&lt;br /&gt;Click on OK. You will be prompted to add a database reference.  Go ahead and select the Northwind database. If it is not already listed in the dialog, add the connection to the Northwind database.&lt;br /&gt;&lt;br /&gt;AddDBRef&lt;br /&gt;&lt;br /&gt;Click on Ok. The SQL Server project should be created by Visual Studio.&lt;br /&gt;&lt;br /&gt;Create a managed stored procedure&lt;br /&gt;&lt;br /&gt;Before we go any further, let's spend a few minutes going over the task we try to implement using the CLR integration. Suppose a business partner of Northwind is placing orders in raw XML messages and the order data needs to be parsed from the XML messages and then be populate into the Northwind..Orders table .&lt;br /&gt;&lt;br /&gt;Let's go back to the SQL Server project we just created. Right click the project file NorthwindOrdersCLR, select Add New Item, choose Stored Procedure from the "Add new item" dialog, rename the stored procedure to ParseOrders.cs and then hit OK.&lt;br /&gt;&lt;br /&gt;CreateSP&lt;br /&gt;&lt;br /&gt;Visual Studio generates the stub for the stored procedure for you automatically.&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;using System.Data;&lt;br /&gt;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;&lt;br /&gt;using System.Data.SqlTypes;&lt;br /&gt;&lt;br /&gt;using Microsoft.SqlServer.Server;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;public partial class StoredProcedures&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;&lt;br /&gt;    public static void ParseOrders()&lt;br /&gt;&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        // Put your code here&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;In CLR, stored procedures are implemented as public static methods of a .NET class. The static methods can either be declared as void, or return an integer value, and the static methods must be marked with the "SqlProcedure" attribute, which is under the Microsoft.SqlServer.Server namespace.&lt;br /&gt;&lt;br /&gt;In order to parse the XML message, we need to reference the System.Xml namesapce. Also, we are going to pass a string parameter to to our stored procedure.  The string will be the raw message of orders from the Northwind's business partner. The stored procedure stub should look like this after the tweaks.&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;using System.Data;&lt;br /&gt;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;&lt;br /&gt;using System.Data.SqlTypes;&lt;br /&gt;&lt;br /&gt;using Microsoft.SqlServer.Server;&lt;br /&gt;&lt;br /&gt;using System.Xml;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;public partial class StoredProcedures&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;&lt;br /&gt;    public static void ParseOrders(string orderXML)&lt;br /&gt;&lt;br /&gt;    ...&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;So far so good. Now we don't need to look at the problem from a database developer's point of view any more. We are back to what we are good at - programming in .NET. We can write this stored procedure in the way we write .NET clients to access the SQL database:  create a database connection, create a SqlCommand with the SQL statement for inserting data, add parameters to the command, parse the XML message, and then call ExecuteNonQuery. In addition, we will benefit from the power of try-catch blocks so we can handle the exceptions in the .NET way.  &lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;using System.Data;&lt;br /&gt;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;&lt;br /&gt;using System.Data.SqlTypes;&lt;br /&gt;&lt;br /&gt;using Microsoft.SqlServer.Server;&lt;br /&gt;&lt;br /&gt;using System.Xml;&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;public partial class StoredProcedures&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    [Microsoft.SqlServer.Server.SqlProcedure]&lt;br /&gt;&lt;br /&gt;    public static void ParseOrders(string orderXML)&lt;br /&gt;&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        XmlDocument xd = new XmlDocument();&lt;br /&gt;&lt;br /&gt;        using (SqlConnection sc = new SqlConnection("context connection=true"))&lt;br /&gt;&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;            using (SqlCommand cmdInsert = new SqlCommand("INSERT INTO Orders (CustomerID, EmployeeID, OrderDate) VALUES (@OrderID, @EmployeeID, @OrderDate)", sc))&lt;br /&gt;&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                try&lt;br /&gt;&lt;br /&gt;                {&lt;br /&gt;&lt;br /&gt;                    xd.LoadXml(orderXML);&lt;br /&gt;&lt;br /&gt;                    sc.Open();&lt;br /&gt;&lt;br /&gt;                    XmlNode orderNode = xd.DocumentElement;&lt;br /&gt;&lt;br /&gt;                    cmdInsert.Parameters.Add("@CustomerID", SqlDbType.NChar, 5).Value = xd["CustomerID"].InnerText;&lt;br /&gt;&lt;br /&gt;                    cmdInsert.Parameters.Add("@EmployeeID", SqlDbType.Int, 4).Value = Convert.ToInt32(xd["EmployeeID"].InnerText);&lt;br /&gt;&lt;br /&gt;                    cmdInsert.Parameters.Add("@OrderDate", SqlDbType.DateTime, 8).Value = Convert.ToDateTime(xd["OrderDate"].InnerText);&lt;br /&gt;&lt;br /&gt;                    cmdInsert.ExecuteNonQuery();&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                catch (XmlException xe)&lt;br /&gt;&lt;br /&gt;                {&lt;br /&gt;&lt;br /&gt;                    SqlContext.Pipe.Send("Error parsing XML message: " + xe.Message);&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                catch (SqlException ex)&lt;br /&gt;&lt;br /&gt;                {&lt;br /&gt;&lt;br /&gt;                    SqlContext.Pipe.Send("Error executing SQL statement: " + ex.Message);&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                finally&lt;br /&gt;&lt;br /&gt;                {&lt;br /&gt;&lt;br /&gt;                    sc.Close();&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;Although the code is pretty self-descriptive and you get the idea of exactly what this stored procedure does, I do need to mention a couple of things here.&lt;br /&gt;&lt;br /&gt;First, the connection string I used to create the SqlConnection looks different from what we usually do in a traditional .NET application. The problem of internal data access is a fairly common scenario. That is, you wish to access the same server on which your CLR stored procedure or function is executing. One option is to create a connection using SqlConnection, specify a connection string that points to the local server, and open the connection. This requires specifying credentials for logging in. The connection is in a different database session than the stored procedure or function, it may have different SET options, it is in a separate transaction, it does not see your temporary tables, and so on. If your managed stored procedure or function code is executing in the SQL Server process, it is because someone connected to that server and executed a SQL statement to invoke it. You probably want the stored procedure or function to execute in the context of that connection, along with its transaction, SET options etc. This is called the context connection. The context connection lets you execute Transact-SQL statements in the same context that your code was invoked in the first place. In order to obtain the context connection, you must use the "context connection" connection string keyword, as in the code snippet above.&lt;br /&gt;&lt;br /&gt;The second thing is that I used SqlContext.Pipe.Send several times in the code. For CLR database objects running in SQL Server, you can send results to the connected pipe using the Send methods of the SqlPipe object. Access the Pipe property of the SqlContext object to obtain the SqlPipe object. The SqlPipe class is conceptually similar to the Response class found in ASP.NET. This is extremely useful when you need to watch the execution steps of CLR objects. We will look at a couple of examples of how this works when we run the stored procedure.&lt;br /&gt;&lt;br /&gt;Deploy the CLR assembly using Visual Studio&lt;br /&gt;&lt;br /&gt;Now that we have created the managed stored procedure to handle the orders in XML format, let's deploy it into SQL server to test it out. Deploying a CLR assembly in Visual Studio cannot be easier. All you have to do is right click the NorthwindOrdersCLR project and choose "Deploy".&lt;br /&gt;&lt;br /&gt;Deploy&lt;br /&gt;&lt;br /&gt;You may receive an error message saying "The current database compatibility level does not support managed objects." This is because the Northwind database was created in SQL Server 2000 and CLR integration only works with SQL Server 2005/2008. We'll fix this quickly by changing the compatibility level of the database to SQL Server 2005(90). Re-deploy the CLR project after you have changed the compatibility level.&lt;br /&gt;&lt;br /&gt;image&lt;br /&gt;&lt;br /&gt;Visual Studio should report "Deploy succeeded" if no errors have occurred. Open SQL Server Management Studio, expand the Northwind database's Programmability node, and you should see the ParseOrders stored procedure listed under "Stored Procedures" and the NorthwindOrdersCLR assembly under the "Assemblies" node.&lt;br /&gt;&lt;br /&gt;image&lt;br /&gt;&lt;br /&gt;Execute CLR objects&lt;br /&gt;&lt;br /&gt;CLR objects can be executed the same way native SQL objects are executed. Simply run the following SQL statement to test our ParseOrders.&lt;br /&gt;&lt;br /&gt;exec ParseOrders '&lt;Order&gt;&lt;CustomerID&gt;FRANK&lt;/CustomerID&gt;&lt;EmployeeID&gt;1&lt;/EmployeeID&gt;&lt;OrderDate&gt;2008/05/02&lt;/OrderDate&gt;&lt;/Order&gt;' &lt;br /&gt;&lt;br /&gt;If you've been following my code so far, you should receive the "Query executed successfully" message when you executed the query above. We can verify the data in the Orders table by executing a quick SELECT statement.&lt;br /&gt;&lt;br /&gt;SELECT * FROM orders WHERE OrderID = (SELECT MAX(OrderID) FROM Orders)&lt;br /&gt;&lt;br /&gt;The new order with CustomerID "FRANK" is shown in the result set.&lt;br /&gt;&lt;br /&gt;image&lt;br /&gt;&lt;br /&gt;I mentioned earlier that the SqlPipe.Send method was very useful for tracing the execution of CLR objects. We can demonstrate this by creating an exception and letting it get caught by the "catch" block, where I called the SqlContext.Pipe.Send to print out the exception message. Execute the SQL statement below.&lt;br /&gt;&lt;br /&gt;exec ParseOrders '&lt;Order&gt;&lt;CustomerID&gt;FRANK&lt;/CustomerID&gt;&lt;EmployeeID&gt;12345&lt;/EmployeeID&gt;&lt;OrderDate&gt;2008/05/02&lt;/OrderDate&gt;&lt;/Order&gt;' &lt;br /&gt;&lt;br /&gt;EmployeeID "12345" doesn't exist in the Northwind..Employees table, so this statement will violate the foreign key constraint on the EmployeeID column in Northwind..Orders.  We expect to see the exception message coming out of the pipe when this query finishes.&lt;br /&gt;&lt;br /&gt;image&lt;br /&gt;&lt;br /&gt;Nice and easy!!! The query executed successfully although the insert command failed due to the constraint. The failure was caught by our SqlException catch block and we got a friendly error message.&lt;br /&gt;&lt;br /&gt;Deploy CLR assemblies into production environment&lt;br /&gt;&lt;br /&gt;It is easy to deploy CLR assemblies with the aid of Visual Studio. But in the production environment, you probably cannot even connect to the SQL server from your Visual Studio. You will need to use the CREATE ASSEMBLY statement in SQL to deploy the assembly. First, copy the compiled DLL file into a path that the SQL Server is able to access. For example, copy the NorthwindOrdersCLR.dll file (located in the bin\debug or bin\release folder under your project folder) to c:\temp on the production SQL server. Open the SQL Management Studio, connect to the production SQL server, and execute the following SQL statement. This will create the CLR assembly in your production database. &lt;br /&gt;&lt;br /&gt;CREATE ASSEMBLY NorthwindOrderCLR from 'c:\helloworld.dll' WITH PERMISSION_SET = SAFE&lt;br /&gt;&lt;br /&gt;The "WITH PERMISSION_SET" option sets the permission the assembly can have when it executes on the SQL server. SAFE is applied by default if not specified otherwise, and SAFE is the most restrictive permission set. Code executed by an assembly with SAFE permissions cannot access external system resources such as files, the network, environment variables, or the registry. Another two possible values for PERMISSION_SET are EXTERNAL_ACCESS and UNSAFE. EXTERNAL_ACCESS enables assemblies to access certain external system resources such as files, networks, environmental variables, and the registry.&lt;br /&gt;UNSAFE enables assemblies unrestricted access to resources, both within and outside an instance of SQL Server. Code running from within an UNSAFE assembly can call unmanaged code as well. SAFE is highly recommended by Microsoft.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-190416191855491596?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/190416191855491596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=190416191855491596' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/190416191855491596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/190416191855491596'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/06/walk-through-of-clr-integration-with.html' title='Walk-through of CLR Integration with SQL Server'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-4574538933703615479</id><published>2009-06-09T21:19:00.000-07:00</published><updated>2009-06-09T22:35:24.302-07:00</updated><title type='text'>CLR Triggers for SQL Server 2005</title><content type='html'>Now Microsoft SQL Server 2005 is integrated with Microsoft .NET Framework Common Language Runtime (CLR), so we can use any .NET Framework language to create database objects. The CLR provides the execution environment for all the server side objects that are created using a .NET language. This means the database developers can now perform tasks that were impossible or difficult to achieve with T-SQL alone. Especially when working with large amounts of server code, developers can easily organize and maintain their code investments.&lt;br /&gt;&lt;br /&gt;This article covers different types of triggers supported by Microsoft SQL Server 2005 with basic ideas about them with an example. It then describes the step-by-step approach to create a CLR trigger (a DML type). &lt;br /&gt;&lt;br /&gt;What is Trigger?&lt;br /&gt;&lt;br /&gt;A trigger is a Database object just like a stored procedure or we can say it is a special kind of Stored procedure which fires after (/before) a specified language event executes. More specifically, it is for the object which is attached to a Table or View or Database schemas for tracking the operations on them. The main difference between a trigger and a stored procedure is that the former is attached to a table or view and is fired only when an INSERT, UPDATE, and/or DELETE occurs, while a stored procedure executes at any time when it is called.&lt;br /&gt;&lt;br /&gt;Types of Triggers&lt;br /&gt;&lt;br /&gt;There are some added types in SQL Server 2005 for triggering actions:&lt;br /&gt;&lt;br /&gt;1.    DML Triggers&lt;br /&gt;&lt;br /&gt;·         AFTER Triggers&lt;br /&gt;&lt;br /&gt;·         INSTEAD OF Triggers&lt;br /&gt;&lt;br /&gt;2.    DDL Triggers&lt;br /&gt;&lt;br /&gt;3.    CLR Triggers&lt;br /&gt;DML Triggers&lt;br /&gt;&lt;br /&gt;These triggers are fired when a Data Manipulation Language (DML) event takes place. These are attached to a Table or View and are fired only when an INSERT, UPDATE and/or DELETE event occurs. The trigger and the statement that fires it are treated as a single transaction. Using this we can cascade changes in related tables, can do check operations for satisfying some rules and can get noticed through firing Mails. We can even execute multiple triggering actions by creating multiple Triggers of same action type on a table. We have to specify the modification action(s) at the Table level that fires the trigger when it is created.&lt;br /&gt;&lt;br /&gt;AFTER Triggers&lt;br /&gt;&lt;br /&gt;As the name specifies, AFTER triggers are executed after the action of the INSERT, UPDATE, or DELETE statement is performed. This is the only option available in earlier versions on Microsoft SQL Server. AFTER triggers can be specified on tables only. Here is a sample trigger creation statement on the Users table.&lt;br /&gt;&lt;br /&gt;Listing 1 (AFTER Trigger example)&lt;br /&gt;&lt;br /&gt;------ Creating a DML trigger in T-SQL -------&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;CREATE TABLE UserTable (User_ID int IDENTITY, User_Name varchar(30), Type varchar(10))&lt;br /&gt;go&lt;br /&gt;CREATE TRIGGER tr_User_INSERT&lt;br /&gt;ON UserTable&lt;br /&gt;FOR INSERT&lt;br /&gt;AS&lt;br /&gt;PRINT GETDATE()&lt;br /&gt;Go&lt;br /&gt;INSERT UserTable (User_Name, Type) VALUES ('James', 'ADMIN')&lt;br /&gt; &lt;br /&gt;------ Result ---------------&lt;br /&gt;Apr 30 2007  7:04AM&lt;br /&gt;&lt;br /&gt;INSTEAD OF Triggers&lt;br /&gt;&lt;br /&gt;INSTEAD OF triggers are executed in place of the usual triggering action. INSTEAD OF triggers can also be defined on views with one or more base tables, where they can extend the types of updates a view can support.&lt;br /&gt;&lt;br /&gt;DDL Triggers&lt;br /&gt;&lt;br /&gt;DDL triggers are new to SQL Server 2005. This type of triggers, like regular triggers, fire stored procedures in response to an event. They fire in response to a variety of Data Definition Language (DDL) events. These events are specified by the T-SQL statements that are start with the keywords CREATE, ALTER, and DROP. Certain stored procedures that perform DDL-like operations can also fire this. These are used for administrative tasks like auditing and regulating database operations.&lt;br /&gt;&lt;br /&gt;CLR Triggers&lt;br /&gt;&lt;br /&gt;A CLR triggers can be any of the above, e.g. can be a DDL or DML one or can also be an AFTER or INSTEAD OF trigger. Here we need to execute one or more methods written in managed codes that are members of an assembly created in the .Net framework. Again, that assembly must be deployed in SQL Server 2005 using CREATE assembly statement. &lt;br /&gt;&lt;br /&gt;The Microsoft.SqlServer.Server Namespace contains the required classes and enumerations for this objective.&lt;br /&gt;&lt;br /&gt;Steps for Creating CLR Trigger&lt;br /&gt;&lt;br /&gt;The following are required steps for creating a CLR-Trigger of DML (After trigger) type for Insert action. This database Object is executed as the result of a user action against a table i.e. for an INSERT statement.&lt;br /&gt;&lt;br /&gt;·         Creating a .NET class of triggering action&lt;br /&gt;&lt;br /&gt;·         Making assembly(.DLL) from that Class&lt;br /&gt;&lt;br /&gt;·         Enabling CLR environment in that database.&lt;br /&gt;&lt;br /&gt;·         Registering the assembly in SQL Server&lt;br /&gt;&lt;br /&gt;·         Creating CLR Trigger using that assembly&lt;br /&gt;&lt;br /&gt;1. Creating a .NET class&lt;br /&gt;&lt;br /&gt;Here we can use any managed language that is supported by .Net Framework such as C++, C#, VB, J#, JScript or XAML, etc. As I am with VB, this managed code is in Visual Basic. Let us discuss the objective of this entity. According to the above example of "tr_User_INSERT" trigger, we have the UserTable for holding the user details. There is a field "Type" which explains the user role (ADMIN, End User, Register User etc.).  Our objective is to check the role of the inserted User for ADMIN type and then do the action as we set.&lt;br /&gt;&lt;br /&gt;Open the notepad, copy the following codes and save it as MyFirstAssembly.vb.&lt;br /&gt;&lt;br /&gt;Listing 2 (.NET Class of Trigger type)&lt;br /&gt;&lt;br /&gt;Imports System.Data&lt;br /&gt;Imports System.Data.SqlClient&lt;br /&gt;Imports Microsoft.SqlServer.Server&lt;br /&gt;Partial Public Class MyFirstClrTrigger&lt;br /&gt;&lt;Microsoft.SqlServer.Server.SqlTrigger(Name&lt;br /&gt; = "checkUserRole", Target&lt;br /&gt; = "UserTable", Event&lt;br /&gt; = "FOR INSERT")&gt; _&lt;br /&gt;   Public Shared Sub checkUserRole()&lt;br /&gt; &lt;br /&gt;Dim triggContext As SqlTriggerContext = SqlContext.TriggerContext()&lt;br /&gt;Dim userType As String = String.Empty&lt;br /&gt; &lt;br /&gt;If triggContext.TriggerAction = TriggerAction.Insert Then&lt;br /&gt;  Using connection As New SqlConnection("context connection=true")&lt;br /&gt;  connection.Open()&lt;br /&gt;  Dim sqlComm As New SqlCommand&lt;br /&gt;  Dim sqlPipe As SqlPipe = SqlContext.Pipe()&lt;br /&gt; &lt;br /&gt;  sqlComm.Connection = connection&lt;br /&gt;  sqlComm.CommandText = "SELECT Type from INSERTED"&lt;br /&gt; &lt;br /&gt;  userType = sqlComm.ExecuteScalar.ToString()&lt;br /&gt; &lt;br /&gt;  If userType.ToUpper = "ADMIN" Then&lt;br /&gt; &lt;br /&gt;    sqlPipe.Send("Hello !!! You have the Admin role.")&lt;br /&gt;    sqlPipe.Send("We can use e-mail codes here to inform.")&lt;br /&gt; &lt;br /&gt;  End If&lt;br /&gt;  End Using&lt;br /&gt;End If&lt;br /&gt;End Sub&lt;br /&gt; &lt;br /&gt;End Class   &lt;br /&gt;&lt;br /&gt;Let us go into the codes. There are two major Namespaces used, System.Data.SqlClient and Microsoft.SqlServer.Server. Microsoft.SqlServer.Server provides the SqlTriggerAttribute Class, which is used to mark a method definition in an assembly as a trigger in SQL Server. The Sqltrigger attribute requires some parameters to set the created trigger properties, such as Name - the name of the Trigger, Target - the table or view to which the trigger applies (in case of DML type) and Event - the event to fire the trigger for (e.g. FOR INSERT, DELETE and/or UPDATE or INSTEAD OF etc.). Again, that method must be a Static (Shared in VB) one; here checkUserRole() is the target method. &lt;br /&gt;&lt;br /&gt;The SqlTriggerContext class provides the required triggering properties of the Trigger for doing action. TriggerAction property of this Class is the global enumeration TriggerAction type of Microsoft.SqlServer.Server namespace which indicates what action fired the Trigger.&lt;br /&gt;&lt;br /&gt;Here we use the INSERTED table, which is automatically created and managed by SQL Server 2005. This is used to set the conditions of DML trigger action. There is also another called DELETED, used in case of delete action. The CLR triggers can access the Inserted or Deleted tables through SqlCommand object using context connection. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Making assembly (.DLL)&lt;br /&gt;&lt;br /&gt;Now we have created the MyFirstAssembly.vb file with MyFirstClrTrigger class, so we need to compile the class to create an assembly. Here I use the VB compiler "vbc.exe," found in .Net   Framework library. Use the following DOS command for creating assembly.&lt;br /&gt;&lt;br /&gt;Listing 3 (compile the .VB file)&lt;br /&gt;&lt;br /&gt;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727&gt;vbc&lt;br /&gt; /t:library /out:F:\CLR_Trigger_Test\CLR_Assembly\MyFirstAssembly&lt;br /&gt; F:\CLR_Trigger_Test\MyFirstClrTrigger.vb&lt;br /&gt;&lt;br /&gt;This command creates a DLL called MyFirstAssembly.dll at out path F:\CLR_Trigger_Test\CLR_Assembly\.&lt;br /&gt;&lt;br /&gt;3. Enabling CLR environment&lt;br /&gt;&lt;br /&gt;By default, the CLR functionality is trued off in SQL Server; so we need to enable it. Use the following T-SQL codes to enable the CLR functionality.&lt;br /&gt;&lt;br /&gt;Listing 4 (enable CLR action)&lt;br /&gt;&lt;br /&gt;------ Enabling CLR action in database -------&lt;br /&gt;sp_configure 'clr enabled', 1&lt;br /&gt;Go&lt;br /&gt;RECONFIGURE with Override&lt;br /&gt;Go&lt;br /&gt;&lt;br /&gt;4. Registering the assembly&lt;br /&gt;&lt;br /&gt;Our next step is to create an assembly in the Database, based on the compiled DLL (MyFirstAssembly.dll). The following T-SQL codes are useful regarding this objective.&lt;br /&gt;&lt;br /&gt;Listing 5 (registering assembly)&lt;br /&gt;&lt;br /&gt;------ Registering an Assembly -------&lt;br /&gt;Create Assembly UserAssembly&lt;br /&gt;From 'F:\CLR_Trigger_Test\CLR_Assembly\MyFirstAssembly.dll'&lt;br /&gt;With Permission_Set=Safe&lt;br /&gt;Go&lt;br /&gt;&lt;br /&gt;For more information about this check my previous article.&lt;br /&gt;&lt;br /&gt;5. Creating CLR Trigger&lt;br /&gt;&lt;br /&gt;Now we will create an extended Trigger using CREATE Trigger statement of T-SQL. There is a new clause named EXTERNAL NAME in SQL Server 2005, which allows us to reference a method of the Registered assembly. By doing so we set the triggering action of our Trigger using that managed code method of the assembly.&lt;br /&gt;&lt;br /&gt;Listing 6 (creating a Trigger)&lt;br /&gt;&lt;br /&gt;------ Creating a DML trigger in CLR -------&lt;br /&gt;Create Trigger tr_User_CheckRole&lt;br /&gt;on UserTable&lt;br /&gt;For INSERT&lt;br /&gt;AS&lt;br /&gt;External Name UserAssembly.MyFirstClrTrigger.checkUserRole&lt;br /&gt;Go&lt;br /&gt;&lt;br /&gt;Here we use the checkUserRole() shared method of our MyFirstClrTrigger class of the registered assembly UserAssembly.&lt;br /&gt;&lt;br /&gt;Checking the triggering action&lt;br /&gt;&lt;br /&gt;Finally, we need to check our Trigger. Let us test the trigger using the same INSERT Statement that we used before.&lt;br /&gt;&lt;br /&gt;Listing 7 (Insert into UserTable)&lt;br /&gt;&lt;br /&gt;----- Checking the DB objects.----------------&lt;br /&gt;INSERT UserTable (User_Name, Type) VALUES ('James', 'ADMIN')&lt;br /&gt;Go&lt;br /&gt;----- Output Message -----&lt;br /&gt;May 2 2007  8:54AM&lt;br /&gt;Hello !!! You have the Admin role.&lt;br /&gt;We can use e-mail codes here to inform.&lt;br /&gt;&lt;br /&gt;The output is the result of two triggering actions; one is of T-SQL type and another one is of CLR type. Both are attached to the UserTable for the same type of action (i.e. after Insert statement).  The following image is the output result window of SQL Server Management studio.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Conclusion&lt;br /&gt;&lt;br /&gt;Now we have our CLR Trigger in our database with source code stored externally. Hence, externally stored code objects can be more secure than the previous one created by T-SQL. Also now we have the power and expressiveness of .NET language for our database objects. Above all, now we have a brief idea about all types of Triggers supported by SQL Server 2005.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-4574538933703615479?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/4574538933703615479/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=4574538933703615479' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/4574538933703615479'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/4574538933703615479'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/06/clr-triggers-for-sql-server-2005.html' title='CLR Triggers for SQL Server 2005'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-8786241821470310426</id><published>2009-06-09T21:14:00.000-07:00</published><updated>2009-06-09T21:19:43.984-07:00</updated><title type='text'>How to Create a SQL Server 2005 Database Snapshot</title><content type='html'>Microsoft SQL Server administrators has a new feature with the SQL Server 2005 Edition which is database snapshots. Database snapshots are new with SQL Server 2005 and only available with Microsoft SQL Server 2005 Enterprise Edition. SQL Server database administration and development with SQL Server especially for sql reporting will be easier with ms sql server database snapshots.&lt;br /&gt;&lt;br /&gt;A database snapshot can be described as a photo of a database. Snapshots are read-only so we can easily say that their main usage areas cover mostly the reporting applications. Database snaphots are one to one the same of the original database at the time when the snapshot is created. After a snapshot is created it stays as a static view of the original database at the time of snapshot creation. A snapshot can persists until it is dropped. Also multiple snapshots can be created with different names of a database called as source database.&lt;br /&gt;&lt;br /&gt;In order to create a database snapshot, CREATE DATABASE statement is used.&lt;br /&gt;&lt;br /&gt;   &lt;br /&gt;&lt;br /&gt;How to Create a SQL Server 2005 Database Snapshot&lt;br /&gt;&lt;br /&gt;Microsoft SQL Server administrators has a new feature with the SQL Server 2005 Edition which is database snapshots. Database snapshots are new with SQL Server 2005 and only available with Microsoft SQL Server 2005 Enterprise Edition. SQL Server database administration and development with SQL Server especially for sql reporting will be easier with ms sql server database snapshots.&lt;br /&gt;&lt;br /&gt;A database snapshot can be described as a photo of a database. Snapshots are read-only so we can easily say that their main usage areas cover mostly the reporting applications. Database snaphots are one to one the same of the original database at the time when the snapshot is created. After a snapshot is created it stays as a static view of the original database at the time of snapshot creation. A snapshot can persists until it is dropped. Also multiple snapshots can be created with different names of a database called as source database.&lt;br /&gt;&lt;br /&gt;In order to create a database snapshot, CREATE DATABASE statement is used.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here is a sample database snapshot create script of the sample database AdventureWorks&lt;br /&gt;&lt;br /&gt;First, in order to place the data files of the snapshot, we should define the physical path of the container folder&lt;br /&gt;&lt;br /&gt;We can use the source database's data folder for the same purpose for snapshot database&lt;br /&gt;&lt;br /&gt;select physical_name from sys.database_files WHERE file_id = 1&lt;br /&gt;&lt;br /&gt;The above query will display where the .mdf file exists. So we can use the same folder. I'm going to use "D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\"&lt;br /&gt;&lt;br /&gt;Considering the below note from Books On Line;&lt;br /&gt;&lt;br /&gt;When you create a database snapshot, the CREATE DATABASE statement cannot reference log files, offline files, restoring files, and defunct files.&lt;br /&gt;&lt;br /&gt;I run the below select statement to get a list of data files that I should reference&lt;br /&gt;&lt;br /&gt;select name from sys.database_files WHERE type_desc = 'ROWS'&lt;br /&gt;&lt;br /&gt;The returned row set only contains the "AdventureWorks_Data"&lt;br /&gt;&lt;br /&gt;Now, we are ready to create a snapshot of the source database.&lt;br /&gt;CREATE DATABASE AdventureWorks_SS ON&lt;br /&gt;(&lt;br /&gt;NAME = AdventureWorks_Data,&lt;br /&gt;FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.ss'&lt;br /&gt;)&lt;br /&gt;AS SNAPSHOT OF AdventureWorks&lt;br /&gt;&lt;br /&gt;After the above command is completed successfully, we can see the snapshot database in the Database Snapshots folder of the SQL Server Instance&lt;br /&gt;&lt;br /&gt;In order to delete or remove a database snapshot after it is not needed any more, you can DROP it by using the DROP DATABASE command&lt;br /&gt;&lt;br /&gt;DROP DATABASE AdventureWorks_SS&lt;br /&gt;&lt;br /&gt;Note that if database snapshot creation fails, the snapshot is in suspect status and it should be deleted or dropped.&lt;br /&gt;&lt;br /&gt;I believe, sql server programmers as well as database administrators will benefit more from Microsoft database snapshots. Especially when sql server performance is an issue than sql server snapshots may be a solution especially for distinguishing reporting databases from the transactional production databases. Administrators or developers do not need to backup and restore sql databases for creating a second database for sql server reporting services, for instance.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-8786241821470310426?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/8786241821470310426/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=8786241821470310426' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8786241821470310426'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8786241821470310426'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/06/how-to-create-sql-server-2005-database.html' title='How to Create a SQL Server 2005 Database Snapshot'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-1707847675986081099</id><published>2009-06-05T12:20:00.001-07:00</published><updated>2009-06-05T12:20:50.003-07:00</updated><title type='text'>Update</title><content type='html'>string conString = GetConnectionString();&lt;br /&gt;                SqlConnection con = new SqlConnection(conString);&lt;br /&gt;                con.Open();&lt;br /&gt;                string sql = "UPDATE    HumanResources.Employee SET ContactID = "+custObj.ContactID+", ManagerID = "+custObj.ManagerID+" WHERE EmployeeID = " + ID;&lt;br /&gt;                SqlCommand cmd = new SqlCommand(sql, con);&lt;br /&gt;                cmd.ExecuteNonQuery();&lt;br /&gt;                con.Close();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-1707847675986081099?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/1707847675986081099/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=1707847675986081099' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1707847675986081099'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1707847675986081099'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/06/update.html' title='Update'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-6138572240577722842</id><published>2009-06-05T11:57:00.000-07:00</published><updated>2009-06-05T11:59:02.988-07:00</updated><title type='text'>Grid View Cell double click</title><content type='html'>private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)&lt;br /&gt;        {&lt;br /&gt;            string ss = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();&lt;br /&gt;&lt;br /&gt;            string gs = dataGridView1.Rows[e.RowIndex].Cells["EmployeeID"].Value.ToString();&lt;br /&gt;&lt;br /&gt;            Class1 test = new Class1();&lt;br /&gt;            DataSet ds = test.GetbyID(gs);&lt;br /&gt;&lt;br /&gt;            textBox1.Text = ds.Tables[0].Rows[0][0].ToString();&lt;br /&gt;            textBox2.Text = ds.Tables[0].Rows[0][1].ToString();&lt;br /&gt;&lt;br /&gt;        }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-6138572240577722842?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/6138572240577722842/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=6138572240577722842' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/6138572240577722842'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/6138572240577722842'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/06/grid-view-cell-double-click.html' title='Grid View Cell double click'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-8664465290490668480</id><published>2009-06-05T11:55:00.000-07:00</published><updated>2009-06-05T11:57:09.885-07:00</updated><title type='text'>Data Retival</title><content type='html'>SqlConnection con = new SqlConnection(conString);&lt;br /&gt;&lt;div style="text-align: left;"&gt; string sql = "Select * from HumanResources.Employee";&lt;br /&gt;&lt;/div&gt; SqlCommand cmd = new SqlCommand(sql, con);&lt;br /&gt; ds = new DataSet();&lt;br /&gt; SqlDataAdapter adpt = new SqlDataAdapter(cmd);&lt;br /&gt;&lt;div style="text-align: left;"&gt; adpt.Fill(ds);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-8664465290490668480?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/8664465290490668480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=8664465290490668480' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8664465290490668480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8664465290490668480'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/06/data-retival.html' title='Data Retival'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-2227315789674975885</id><published>2009-04-03T01:57:00.000-07:00</published><updated>2009-04-03T01:58:57.177-07:00</updated><title type='text'>Nested Case statements</title><content type='html'>(CASE&lt;br /&gt;WHEN custid is not NULL THEN custid&lt;br /&gt;WHEN  accountid is not null THEN accountid&lt;br /&gt;Else refID&lt;br /&gt;END) AS TranNo&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-2227315789674975885?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/2227315789674975885/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=2227315789674975885' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/2227315789674975885'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/2227315789674975885'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/04/nested-case-statements.html' title='Nested Case statements'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-8227937537440764294</id><published>2009-02-21T21:10:00.000-08:00</published><updated>2009-02-21T21:11:00.402-08:00</updated><title type='text'>Get Computer Serial number..</title><content type='html'>&lt;p&gt;With "GetVolumeInformation", the signature looks as follows:&lt;/p&gt;       &lt;p&gt;&lt;span style="font-family:Courier New, Courier, mono;color:#0000ff;"&gt;[DllImport("kernel32.dll")]&lt;br /&gt;        private static extern long GetVolumeInformation(string PathName, StringBuilder          VolumeNameBuffer, UInt32 VolumeNameSize, ref UInt32 VolumeSerialNumber,          ref UInt32 MaximumComponentLength, ref UInt32 FileSystemFlags, StringBuilder          FileSystemNameBuffer, UInt32 FileSystemNameSize);&lt;/span&gt;&lt;/p&gt;       &lt;p&gt;Note that some of the parameters that you would think would be of type          "int" must be passed as "UInt32", which corresponds          to the .NET type "uint", and oftentimes a string must be passed          as StringBuilder.&lt;/p&gt;       &lt;p&gt;The actual method , with a string return value for convenience, looks          like this:&lt;/p&gt;       &lt;p&gt;&lt;span style="font-family:Courier New, Courier, mono;color:#0000ff;"&gt;public string GetVolumeSerial(string strDriveLetter)&lt;br /&gt;        {&lt;br /&gt;        uint serNum = 0;&lt;br /&gt;        uint maxCompLen = 0;&lt;br /&gt;        StringBuilder VolLabel = new StringBuilder(256); // Label&lt;br /&gt;        UInt32 VolFlags = new UInt32();&lt;br /&gt;        StringBuilder FSName = new StringBuilder(256); // File System Name&lt;br /&gt;        strDriveLetter+=":\\"; // fix up the passed-in drive letter          for the API call&lt;br /&gt;        long Ret = GetVolumeInformation(strDriveLetter, VolLabel, (UInt32)VolLabel.Capacity,          ref serNum, ref maxCompLen, ref VolFlags, FSName, (UInt32)FSName.Capacity);&lt;/span&gt;&lt;/p&gt;       &lt;p&gt;&lt;span style="font-family:Courier New, Courier, mono;color:#0000ff;"&gt;return Convert.ToString(serNum);&lt;br /&gt;        }&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-8227937537440764294?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/8227937537440764294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=8227937537440764294' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8227937537440764294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8227937537440764294'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/02/get-computer-serial-number.html' title='Get Computer Serial number..'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-5234081117184783420</id><published>2009-01-13T02:53:00.000-08:00</published><updated>2009-01-13T03:25:35.782-08:00</updated><title type='text'>Creating Non-Rectangular Forms</title><content type='html'>&lt;p&gt;   &lt;span style="font-family:Verdana,Arial,Helvetica;"&gt; &lt;!--content_start--&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;This is Taken from Net and this is only for educational purpose only&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;It is amazingly easy to create forms of any size and shape within Visual C#. You can even do it with VB .NET! For the most part, this can be broken down into the following steps:&lt;/span&gt;&lt;/p&gt;  &lt;ol&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;li&gt;Create a background image for the form &lt;/li&gt;&lt;li&gt;Set background of image to a color for transparency &lt;/li&gt;&lt;li&gt;Create a project in Visual Studio .NET &lt;/li&gt;&lt;li&gt; Set a couple of property on the form to set the transparency color and to turn off the title bar. &lt;/li&gt;&lt;/span&gt;&lt;/ol&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;The following walks you through each of these steps.&lt;/span&gt;&lt;/p&gt;  &lt;h3&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Creating the Background Image&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;To create a non-rectangular form, the first step is to create an image that will be used for your background. You can use any program to create your image as long as you can save into a standard format. In general, I use Microsoft Paint since it comes with Windows. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Open Paint and draw an image for your form. I created the image shown in Figure 1 as my non-rectangular form. Be aware, I am a developer and not a graphics artist! &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;img src="http://www.developer.com/img/2005/07/NonRecForm01.GIF" /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;b&gt;Figure 1:&lt;/b&gt;&lt;i&gt; The initial drawing of the non-rectangular form.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;It is by using transparency that a non-rectangular form is created. Once you've created your form in your drawing program, you will need to set the remaining background of your image to a color that will be made transparent. In Microsoft Paint, you can select and use a color that you know will not be used elsewhere within your application for forms, buttons, controls, or anything else that will be displayed. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Rather than selecting one of the existing colors, I tend to create a custom color to use. That way I'll know its exact value. To do this in page, select Colors | Edit Colors... to get the Edit Colors Dialog. You can then click on the Define Custom Colors &gt;&gt; button to expand out the dialog so that you can create a custom color. Within the expanded dialog (shown in Figure 2) I use the values of 100 for Red, 0 for Green, and 0 for Blue. This produces a maroon looking color. &lt;/span&gt;&lt;/p&gt;    &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;a href="http://www.developer.com/img/2005/07/NonRecForm02.GIF" target="newFrame"&gt;  &lt;img src="http://www.developer.com/img/2005/07/NonRecForm02.GIF" width="500" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;b&gt;Figure 2:&lt;/b&gt;&lt;i&gt; Creating a custom color in Microsoft Paint.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Clicking OK saves this color. You can then use it to fill the background of your image. I've done this as shown in Figure 3. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;img src="http://www.developer.com/img/2005/07/NonRecForm03.GIF" /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;b&gt;Figure 3:&lt;/b&gt;&lt;i&gt; The non-rectangular form with a custom background color.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Now that you have an image to use as your form, save it so that you can use it within Visual Studio .NET&lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Creating the Visual Studio .NET Project&lt;/span&gt;&lt;/h3&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Open Visual Studio .NET and create a new project. You can create either a C# Windows form or a Visual Basic Windows Form project. I use C# in this article, but the steps are identical for Visual Basic .NET. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Your project will start out with the standard rectangular Windows form. This, however, will be changed. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Select the form and then display the properties. Change the &lt;b&gt;BackgroundImage&lt;/b&gt; property the form you created. You may need to then resize the form displayed in the Design editor so that your entire background image is displayed. I've done this in Figure 4 with my form. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;a href="http://www.developer.com/img/2005/07/NonRecForm04.GIF" target="newFrame"&gt;  &lt;img src="http://www.developer.com/img/2005/07/NonRecForm04.GIF" width="500" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;b&gt;Figure 4:&lt;/b&gt;&lt;i&gt; The non-rectangular form image within the Design editor of Visual Studio .NET 2005.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;In order to drop out the custom color you created, you need to set the &lt;b&gt;TransparencyKey&lt;/b&gt; property. To set this property, click on the down arrow next to the entry box. This will display a color dialog with tabs. Select the Custom tab to ensure that the dialog displays similarly to Figure 5. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;img src="http://www.developer.com/img/2005/07/NonRecForm05.GIF" /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;b&gt;Figure 5:&lt;/b&gt;&lt;i&gt; The Custom tab in the TransparencyKey color selection dialog box.&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Right click on one of the empty color boxes in this dialog. This will bring up the dialog for defining a custom color similar to what you saw in Microsoft Paint. Set the colors to the same values you did in Paint (Red 100, Green 0, Blue 0). Click the Add Color button to save this color. This also sets the &lt;b&gt;TransparencyKey&lt;/b&gt; property to the color you created. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Now that you've set the background color to be transparent, the remaining step is to get rid of a few items that will make your form looking goofy. Because you are using a non-rectangular form, the Title bar will no longer look good floating above your form. Additionally, your form is not set up to be resized. As such, you should set the &lt;b&gt;FormBorderStyle&lt;/b&gt; property to the value of &lt;b&gt;None&lt;/b&gt;. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Because you've now turned off the title bar, you will need to make sure your form has a way to exit. For the example I created in the attached zip, I simply dropped a button onto the form and put an Application.End() command into it. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;You should now be able to build and run your form as I've done in Figure 6. Of course, the colors looked okay on the screen. The dithering is a result of my capturing the image. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;a href="http://www.developer.com/img/2005/07/NonRecForm06.GIF" target="newFrame"&gt;  &lt;img src="http://www.developer.com/img/2005/07/NonRecForm06.GIF" width="500" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;&lt;b&gt;Figure 6:&lt;/b&gt;&lt;i&gt; The final form on Windows. &lt;/i&gt;&lt;/span&gt;&lt;/p&gt;   &lt;h3&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;In Conclusion...&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;In conclusion, creating a custom form is simple. Once you've done the above process, you can drag and drop any controls and features onto your form as you'd like. Creating the rest of a form's functionality does not change from the way you've done it before. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-family:Verdana,Arial,Helvetica;"&gt;Granted, there are a few things you may want to do such as create non-rectangular buttons, add drag&amp;amp;drop functionality, resize the form, and add other title button functionality back onto the form. This can all be done, but they are tasks for other articles! &lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-5234081117184783420?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/5234081117184783420/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=5234081117184783420' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/5234081117184783420'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/5234081117184783420'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/01/creating-non-rectangular-forms.html' title='Creating Non-Rectangular Forms'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-8410294987630048228</id><published>2009-01-07T22:22:00.000-08:00</published><updated>2009-01-07T22:23:38.501-08:00</updated><title type='text'>How to Convert in SQL</title><content type='html'>Convert(Data Type, Field Name)&lt;br /&gt;&lt;br /&gt;Eg: Convert(int,Qty)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-8410294987630048228?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/8410294987630048228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=8410294987630048228' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8410294987630048228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8410294987630048228'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2009/01/how-to-convert-in-sql.html' title='How to Convert in SQL'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-6001228020977838837</id><published>2008-12-29T22:18:00.000-08:00</published><updated>2008-12-29T22:24:22.120-08:00</updated><title type='text'>How to find the number of feilds in a table</title><content type='html'>select COUNT(*) as ColumnCount from information_schema.columns&lt;br /&gt;where table_name = 'table_name'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-6001228020977838837?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/6001228020977838837/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=6001228020977838837' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/6001228020977838837'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/6001228020977838837'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/12/how-to-find-number-of-feilds-in-table.html' title='How to find the number of feilds in a table'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-8530420864872592875</id><published>2008-12-22T21:01:00.000-08:00</published><updated>2008-12-22T21:03:06.145-08:00</updated><title type='text'>Visual Studio .NET 2003 Keyboard Shortcuts</title><content type='html'>http://www.codinghorror.com/blog/files/Visual%20Studio%20.NET%202003%20Keyboard%20Shortcuts.htm&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-8530420864872592875?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/8530420864872592875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=8530420864872592875' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8530420864872592875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8530420864872592875'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/12/visual-studio-net-2003-keyboard.html' title='Visual Studio .NET 2003 Keyboard Shortcuts'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-7123254104962628063</id><published>2008-12-16T03:21:00.000-08:00</published><updated>2008-12-16T03:22:57.991-08:00</updated><title type='text'>More date formats that does not come standard in SQL Server as part of the CONVERT function</title><content type='html'>&lt;sup style="color: red;"&gt;1&lt;/sup&gt; To make the month name in upper case, simply use               the UPPER string function.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table class="bodytext" style="font-size: 10px;" border="1" cellpadding="3" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr style="font-weight: bold; color: rgb(255, 255, 255);" align="center" bgcolor="#669900"&gt;&lt;td colspan="2"&gt;&lt;br /&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr style="font-weight: bold;" align="center" bgcolor="#ccff99"&gt;                              &lt;td&gt;SQL Statement&lt;/td&gt;               &lt;td&gt;Sample Output&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;                &lt;div&gt;SELECT SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 120), 3, 8) AS [YY-MM-DD]&lt;/div&gt;                &lt;div&gt;SELECT REPLACE(CONVERT(VARCHAR(8), GETDATE(), 11), '/', '-') AS [YY-MM-DD]&lt;/div&gt;               &lt;/td&gt;               &lt;td align="center"&gt;99-01-24&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;                &lt;div&gt;SELECT CONVERT(VARCHAR(10), GETDATE(), 120) AS [YYYY-MM-DD]&lt;/div&gt;                &lt;div&gt;SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 111), '/', '-') AS [YYYY-MM-DD]&lt;/div&gt;               &lt;/td&gt;               &lt;td align="center"&gt;1999-01-24&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT RIGHT(CONVERT(VARCHAR(8), GETDATE(), 3), 5) AS [MM/YY]&lt;br /&gt;               SELECT SUBSTRING(CONVERT(VARCHAR(8), GETDATE(), 3), 4, 5) AS [MM/YY]&lt;/td&gt;               &lt;td align="center"&gt;08/99&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT RIGHT(CONVERT(VARCHAR(10), GETDATE(), 103), 7) AS [MM/YYYY]&lt;/td&gt;               &lt;td align="center"&gt;12/2005&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT CONVERT(VARCHAR(5), GETDATE(), 11) AS [YY/MM]&lt;/td&gt;               &lt;td align="center"&gt;99/08&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td style="height: 23px;"&gt;SELECT CONVERT(VARCHAR(7), GETDATE(), 111) AS [YYYY/MM]&lt;/td&gt;               &lt;td style="height: 23px;" align="center"&gt;2005/12&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT DATENAME(MM, GETDATE()) + RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9)                 AS [Month DD, YYYY]&lt;/td&gt;               &lt;td align="center"&gt;July 04, 2006 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT SUBSTRING(CONVERT(VARCHAR(11), GETDATE(), 113), 4, 8) AS [Mon YYYY]&lt;/td&gt;               &lt;td align="center"&gt;Apr 2006 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT DATENAME(MM, GETDATE()) + ' ' + CAST(YEAR(GETDATE()) AS VARCHAR(4)) AS                 [Month YYYY]               &lt;/td&gt;               &lt;td align="center"&gt;February 2006 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) AS                 [DD Month]&lt;/td&gt;               &lt;td align="center"&gt;11 September &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT DATENAME(MM, GETDATE()) + ' ' + CAST(DAY(GETDATE()) AS VARCHAR(2)) AS                 [Month DD]&lt;/td&gt;               &lt;td align="center"&gt;September 11 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) + ' '                 + RIGHT(CAST(YEAR(GETDATE()) AS VARCHAR(4)), 2) AS [DD Month YY]&lt;/td&gt;               &lt;td align="center"&gt;19 February 72 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) + ' '                 + CAST(YEAR(GETDATE()) AS VARCHAR(4)) AS [DD Month YYYY]&lt;/td&gt;               &lt;td align="center"&gt;11 September 2002 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT RIGHT(CONVERT(VARCHAR(8), GETDATE(), 5), 5) AS [MM-YY]&lt;br /&gt;               SELECT SUBSTRING(CONVERT(VARCHAR(8), GETDATE(), 5), 4, 5) AS [MM-YY]&lt;/td&gt;               &lt;td align="center"&gt;12/92&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT RIGHT(CONVERT(VARCHAR(10), GETDATE(), 105), 7) AS [MM-YYYY]&lt;/td&gt;               &lt;td align="center"&gt;05-2006&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT RIGHT(CONVERT(VARCHAR(7), GETDATE(), 120), 5) AS [YY-MM]&lt;br /&gt;               SELECT SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 120), 3, 5) AS [YY-MM]&lt;/td&gt;               &lt;td align="center"&gt;92/12&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT CONVERT(VARCHAR(7), GETDATE(), 120) AS [YYYY-MM]&lt;/td&gt;               &lt;td align="center"&gt;2006-05&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 1), '/', '') AS [MMDDYY]&lt;/td&gt;               &lt;td align="center"&gt;122506&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') AS [MMDDYYYY]&lt;/td&gt;               &lt;td align="center"&gt;12252006&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 3), '/', '') AS [DDMMYY]&lt;/td&gt;               &lt;td align="center"&gt;240702&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 103), '/', '') AS [DDMMYYYY]&lt;/td&gt;               &lt;td align="center"&gt;24072002&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT REPLACE(RIGHT(CONVERT(VARCHAR(9), GETDATE(), 6), 6), ' ', '-') AS                 [Mon-YY]&lt;/td&gt;               &lt;td align="center"&gt;Sep-02 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT REPLACE(RIGHT(CONVERT(VARCHAR(11), GETDATE(), 106), 8), ' ', '-') AS                 [Mon-YYYY]&lt;/td&gt;               &lt;td align="center"&gt;Sep-2002 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT REPLACE(CONVERT(VARCHAR(9), GETDATE(), 6), ' ', '-') AS [DD-Mon-YY]&lt;/td&gt;               &lt;td align="center"&gt;25-Dec-05 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                              &lt;td&gt;SELECT REPLACE(CONVERT(VARCHAR(11), GETDATE(), 106), ' ', '-') AS [DD-Mon-YYYY]&lt;/td&gt;               &lt;td align="center"&gt;25-Dec-2005 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-7123254104962628063?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/7123254104962628063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=7123254104962628063' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/7123254104962628063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/7123254104962628063'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/12/more-date-formats-that-does-not-come.html' title='More date formats that does not come standard in SQL Server as part of the CONVERT function'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-749065613302492272</id><published>2008-12-16T02:56:00.000-08:00</published><updated>2008-12-16T03:21:16.625-08:00</updated><title type='text'>SQL Server Date Formats</title><content type='html'>&lt;table class="bodytext" style="font-size: 10px;" border="1" cellpadding="3" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr style="font-weight: bold; color: rgb(255, 255, 255);" align="center" bgcolor="#669900"&gt;&lt;td colspan="2"&gt;&lt;br /&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr style="font-weight: bold;" align="center" bgcolor="#ccff99"&gt;                                             &lt;td&gt;SQL Statement&lt;/td&gt;               &lt;td&gt;Sample Output&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(20), GETDATE(), 100)&lt;/td&gt;               &lt;td align="center"&gt;Jan 1 2005 1:29PM &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [MM/DD/YY]&lt;/td&gt;               &lt;td align="center"&gt;11/23/98&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY]&lt;/td&gt;               &lt;td align="center"&gt;11/23/1998&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(8), GETDATE(), 2) AS [YY.MM.DD]&lt;/td&gt;               &lt;td align="center"&gt;72.01.01&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY.MM.DD]&lt;/td&gt;               &lt;td align="center"&gt;1972.01.01&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(8), GETDATE(), 3) AS [DD/MM/YY]&lt;/td&gt;               &lt;td align="center"&gt;19/02/72&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY]&lt;/td&gt;               &lt;td align="center"&gt;19/02/1972&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(8), GETDATE(), 4) AS [DD.MM.YY]&lt;/td&gt;               &lt;td align="center"&gt;25.12.05&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(10), GETDATE(), 104) AS [DD.MM.YYYY]&lt;/td&gt;               &lt;td align="center"&gt;25.12.2005&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(8), GETDATE(), 5) AS [DD-MM-YY]&lt;/td&gt;               &lt;td align="center"&gt;24-01-98&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(10), GETDATE(), 105) AS [DD-MM-YYYY]&lt;/td&gt;               &lt;td align="center"&gt;24-01-1998&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(9), GETDATE(), 6) AS [DD MON YY]&lt;/td&gt;               &lt;td align="center"&gt;04 Jul 06 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(11), GETDATE(), 106) AS [DD MON YYYY]&lt;/td&gt;               &lt;td align="center"&gt;04 Jul 2006 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(10), GETDATE(), 7) AS [Mon DD, YY]&lt;/td&gt;               &lt;td align="center"&gt;Jan 24, 98 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(12), GETDATE(), 107) AS [Mon DD, YYYY]&lt;/td&gt;               &lt;td align="center"&gt;Jan 24, 1998 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(8), GETDATE(), 108)&lt;/td&gt;               &lt;td align="center"&gt;03:24:53&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(26), GETDATE(), 109)&lt;/td&gt;               &lt;td align="center"&gt;Apr 28 2006 12:32:29:253PM &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(8), GETDATE(), 10) AS [MM-DD-YY]&lt;/td&gt;               &lt;td align="center"&gt;01-01-06&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(10), GETDATE(), 110) AS [MM-DD-YYYY]&lt;/td&gt;               &lt;td align="center"&gt;01-01-2006&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(8), GETDATE(), 11) AS [YY/MM/DD]&lt;/td&gt;               &lt;td align="center"&gt;98/11/23&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(10), GETDATE(), 111) AS [YYYY/MM/DD]&lt;/td&gt;               &lt;td align="center"&gt;1998/11/23&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(6), GETDATE(), 12) AS [YYMMDD]&lt;/td&gt;               &lt;td align="center"&gt;980124&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(8), GETDATE(), 112) AS [YYYYMMDD]&lt;/td&gt;               &lt;td align="center"&gt;19980124&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(24), GETDATE(), 113)&lt;/td&gt;               &lt;td align="center"&gt;28 Apr 2006 00:34:55:190 &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(12), GETDATE(), 114) AS [HH:MI:SS:MMM(24H)]&lt;/td&gt;               &lt;td align="center"&gt;11:34:23:013&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(19), GETDATE(), 120)&lt;/td&gt;               &lt;td align="center"&gt;1972-01-01 13:42:24&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(23), GETDATE(), 121)&lt;/td&gt;               &lt;td align="center"&gt;1972-02-19 06:35:24.489&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(23), GETDATE(), 126)&lt;/td&gt;               &lt;td align="center"&gt;1998-11-23T11:25:43:250&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(26), GETDATE(), 130)&lt;/td&gt;               &lt;td align="center"&gt;28 Apr 2006 12:39:32:429AM &lt;sup style="color: red;"&gt;1&lt;/sup&gt;&lt;/td&gt;              &lt;/tr&gt;              &lt;tr&gt;                                             &lt;td&gt;SELECT CONVERT(VARCHAR(25), GETDATE(), 131)&lt;/td&gt;               &lt;td align="center"&gt;28/04/2006 12:39:32:429AM&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-749065613302492272?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/749065613302492272/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=749065613302492272' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/749065613302492272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/749065613302492272'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/12/sql-server-date-formats.html' title='SQL Server Date Formats'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-3793134508080728929</id><published>2008-12-14T21:21:00.000-08:00</published><updated>2008-12-14T21:22:36.721-08:00</updated><title type='text'>Forcing console logins when the server exceeds its terminal services connections</title><content type='html'>&lt;b&gt;&lt;span style="font-size:180%;"&gt;MsTSC /Console&lt;/span&gt;&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-3793134508080728929?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/3793134508080728929/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=3793134508080728929' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/3793134508080728929'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/3793134508080728929'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/12/forcing-console-logins-when-server.html' title='Forcing console logins when the server exceeds its terminal services connections'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-208613858552735063</id><published>2008-12-11T00:29:00.000-08:00</published><updated>2008-12-11T00:31:10.702-08:00</updated><title type='text'>Check for an Integer Value-Without Exception</title><content type='html'>bool isvalid;&lt;br /&gt;            int number;&lt;br /&gt;&lt;br /&gt;            isvalid = int.TryParse(textBox1.Text,out number);&lt;br /&gt;&lt;br /&gt;            if (isvalid)&lt;br /&gt;            {&lt;br /&gt;                MessageBox.Show("Number");&lt;br /&gt;            }&lt;br /&gt;            if (isvalid == false)&lt;br /&gt;            {&lt;br /&gt;                MessageBox.Show("Not a number");&lt;br /&gt;            }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-208613858552735063?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/208613858552735063/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=208613858552735063' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/208613858552735063'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/208613858552735063'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/12/check-for-integer-value-without.html' title='Check for an Integer Value-Without Exception'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-4245890673090580408</id><published>2008-12-08T22:13:00.000-08:00</published><updated>2008-12-08T22:17:07.069-08:00</updated><title type='text'>How to get configuraion Settings</title><content type='html'>It is not enough to add the reference in the code. You have to manually add the reference using Add reference. If not ConfigurationManager wont visible.&lt;br /&gt;&lt;br /&gt;using System.Collections.Specialized;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.Configuration;&lt;br /&gt;&lt;br /&gt;NameValueCollection appSettings = ConfigurationManager.AppSettings;&lt;br /&gt;&lt;br /&gt;string userName = appSettings["UserName"].ToString();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-4245890673090580408?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/4245890673090580408/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=4245890673090580408' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/4245890673090580408'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/4245890673090580408'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/12/how-to-get-configuraion-settings.html' title='How to get configuraion Settings'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-5155594837467746275</id><published>2008-12-08T20:28:00.000-08:00</published><updated>2008-12-08T20:30:24.884-08:00</updated><title type='text'>RUN a SP</title><content type='html'>SqlConnection con=new SqlConnection("User ID=" + ConfigurationSettings.AppSettings.Get("UserName").ToString() + ";Password=" + ConfigurationSettings.AppSettings.Get("Password").ToString() + ";Initial Catalog=" + ConfigurationSettings.AppSettings.Get("DBName").ToString() + ";Data Source=" + ConfigurationSettings.AppSettings.Get("ServerName").ToString() + ";Persist Security Info= true;");&lt;br /&gt;            con.Open();&lt;br /&gt;            SqlCommand cmd=new SqlCommand("SPNAME",con);&lt;br /&gt;            cmd.CommandType = CommandType.StoredProcedure;&lt;br /&gt;            cmd.Parameters.Add(new SqlParameter("@SPPARAM", PARAM));&lt;br /&gt;            cmd.CommandTimeout=0;&lt;br /&gt;            SqlTransaction t=con.BeginTransaction();&lt;br /&gt;            cmd.Transaction=t;&lt;br /&gt;&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                cmd.ExecuteNonQuery();&lt;br /&gt;                t.Commit();&lt;br /&gt;                con.Close();&lt;br /&gt;            }&lt;br /&gt;            catch(Exception ex)&lt;br /&gt;            {&lt;br /&gt;                t.Rollback();&lt;br /&gt;                con.Close();&lt;br /&gt;                string s = ex.Message;&lt;br /&gt;            }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-5155594837467746275?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/5155594837467746275/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=5155594837467746275' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/5155594837467746275'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/5155594837467746275'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/12/run-sp.html' title='RUN a SP'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-7266312552491598836</id><published>2008-12-08T20:25:00.000-08:00</published><updated>2008-12-08T20:28:16.800-08:00</updated><title type='text'>Creating a transaction</title><content type='html'>SqlConnection con=new SqlConnection("User ID=" + ConfigurationSettings.AppSettings.Get("UserName").ToString() + ";Password=" + ConfigurationSettings.AppSettings.Get("Password").ToString() + ";Initial Catalog=" + ConfigurationSettings.AppSettings.Get("DBName").ToString() + ";Data Source=" + ConfigurationSettings.AppSettings.Get("ServerName").ToString() + ";Persist Security Info= true;");&lt;br /&gt;                con.Open();&lt;br /&gt;                SqlCommand cmd=new SqlCommand(sql,con);&lt;br /&gt;                cmd.CommandTimeout=0;&lt;br /&gt;                SqlTransaction t=con.BeginTransaction();&lt;br /&gt;                cmd.Transaction=t;&lt;br /&gt;                try&lt;br /&gt;                {&lt;br /&gt;                    SqlDataAdapter adpt=new SqlDataAdapter(cmd);&lt;br /&gt;           &lt;br /&gt;                    adpt.Fill(dsTemp);&lt;br /&gt;                   t.Commit();&lt;br /&gt;                    con.Close();&lt;br /&gt;                    return ds;&lt;br /&gt;               }&lt;br /&gt;               catch(Exception ex)&lt;br /&gt;                {&lt;br /&gt;                    t.Rollback();&lt;br /&gt;                    con.Close();&lt;br /&gt;                    return new DataSet();&lt;br /&gt;                }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-7266312552491598836?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/7266312552491598836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=7266312552491598836' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/7266312552491598836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/7266312552491598836'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/12/creating-transaction.html' title='Creating a transaction'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-1170767625245374870</id><published>2008-10-20T05:03:00.000-07:00</published><updated>2008-10-20T05:08:53.845-07:00</updated><title type='text'>Nested Case sql</title><content type='html'>(CASE&lt;br /&gt;WHEN(Status = 'Goods Issued')&lt;br /&gt;OR (Status  = 'Partially Issued')&lt;br /&gt;THEN IssuedQty&lt;br /&gt;ELSE '0' END)&lt;br /&gt;AS QTYISSUED&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-1170767625245374870?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/1170767625245374870/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=1170767625245374870' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1170767625245374870'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1170767625245374870'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/10/nested-case-sql.html' title='Nested Case sql'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-8395850826187857585</id><published>2008-10-20T02:49:00.000-07:00</published><updated>2008-10-20T02:50:45.362-07:00</updated><title type='text'>How to get length of data in Text, NText and Image columns in SQL Server</title><content type='html'>&lt;p&gt;&lt;u&gt;&lt;b&gt;Problem&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;There is sometimes a need to figure out the maximum space that is being used by a particular column in your database.  You would initially think that the &lt;a href="http://msdn2.microsoft.com/en-us/library/ms190329.aspx" target="_blank"&gt;LEN()&lt;/a&gt; function would allow you to do this, but this function does not work on Text, NText or Image data types, so how do you figure out the length of a value in a column that has one of these data types?&lt;/p&gt; &lt;p&gt;&lt;u&gt;&lt;b&gt;Solution&lt;br /&gt;&lt;/b&gt;&lt;/u&gt;In addition to the LEN() function, SQL Server also has a &lt;a href="http://msdn2.microsoft.com/en-us/library/ms173486.aspx" target="_blank"&gt;DATALENGTH()&lt;/a&gt; function.  This function can be used on all data types in your table.&lt;/p&gt; &lt;p&gt;Here is an example of running these commands on an IMAGE data type using the LEN function:&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; name, &lt;span style="color:#ff00ff;"&gt;LEN&lt;/span&gt;(packagedata) &lt;span style="color:#0000ff;"&gt;&lt;br /&gt;FROM&lt;/span&gt; dbo.sysdtspackages&lt;/span&gt;&lt;/p&gt; &lt;p&gt;query results&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;br /&gt;&lt;img src="http://www.mssqltips.com/tipimages/1188_len_error.gif" width="546" border="0" height="42" /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;Here is an example of running these commands on an IMAGE data type using the DATALENGTH function:&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; name, &lt;span style="color:#ff00ff;"&gt;DATALENGTH&lt;/span&gt;(packagedata) &lt;span style="color:#0000ff;"&gt;&lt;br /&gt;FROM&lt;/span&gt; dbo.sysdtspackages&lt;/span&gt;&lt;/p&gt; &lt;p&gt;query results&lt;br /&gt;&lt;img src="http://www.mssqltips.com/tipimages/1188_datalength_1.gif" width="429" border="0" height="91" /&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;If you wanted to find out the maximum length used for all of your records you could issue a command such as the following:&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT TOP&lt;/span&gt; 1 name, &lt;span style="color:#ff00ff;"&gt;DATALENGTH&lt;/span&gt;(packagedata) &lt;span style="color:#0000ff;"&gt;&lt;br /&gt;FROM&lt;/span&gt; dbo.sysdtspackages &lt;span style="color:#0000ff;"&gt;&lt;br /&gt;ORDER BY&lt;/span&gt; 2 &lt;span style="color:#0000ff;"&gt;DESC&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;img src="http://www.mssqltips.com/tipimages/1188_datalength_2.gif" width="310" border="0" height="41" /&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;That is all there is to it.  Another little function that you probably won't use often, but this is helpful to know it is there when you do need to use it.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-8395850826187857585?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/8395850826187857585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=8395850826187857585' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8395850826187857585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8395850826187857585'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/10/how-to-get-length-of-data-in-text-ntext.html' title='How to get length of data in Text, NText and Image columns in SQL Server'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-6482695130974278305</id><published>2008-05-12T22:46:00.000-07:00</published><updated>2008-05-12T22:48:23.340-07:00</updated><title type='text'>Working with Timer Control in C#</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The &lt;strong&gt;Timer&lt;/strong&gt; control allows you to set a time interval to execute an event after that interval continuously. It is useful when you want to execute certain applications after a certain interval. Say you want to create a backup of your data processing in every hour. You can make a routine which will take the backup and call that routine on Timer's event and set timer interval for an hour.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Using timer control is pretty simple. To test the control, I'm going to create a Windows Application. I also add two button controls to the form and change their text to Start and Stop as you can see from the following Figure.&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithTimerControlinCSharp11302005054911AM/Images/TimerUpdatedMCB.2.gif" align="bottom" border="0" hspace="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;In this application, I'm going to create a text file mcb.txt in your C:\temp directory and start writing the time after 5 seconds interval. Stop button stops the timer and Start again start the timer.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Now you can drag a timer control from the toolbox to the form. You can set timer properties from the IDE as well as programmatically. To set the timer properties, right click on the timer control and change Interval property. As you can see from the Figure,&lt;br /&gt;&lt;br /&gt;I put 5000 milliseconds (5 seconds).&lt;br /&gt;&lt;br /&gt;I sec = 1000 milliseconds (In case your mathematics is poor as mine ;).&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithTimerControlinCSharp11302005054911AM/Images/TimerUpdatedMCB.3.gif" align="bottom" border="0" hspace="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Now click on the Events button and write event for the timer click as you can see from the following figure.&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithTimerControlinCSharp11302005054911AM/Images/TimerUpdatedMCB.3.gif" align="bottom" border="0" hspace="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Now I add a FileStream and a StreamWriter object in the beginning of the class. As you can see from the following code, FileStream class creates a mcb.txt file and StreamWriter will be used to write to the file.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; FileStream fs = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; FileStream(@"c:\temp\mcb.txt", FileMode.OpenOrCreate, FileAccess.Write);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; StreamWriter m_streamWriter = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; StreamWriter(fs);&lt;br /&gt;&lt;br /&gt;Now write the following code on the Form Load event:&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Form1_Load(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#008000;"&gt;// Write to the file using StreamWriter class&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);&lt;br /&gt;m_streamWriter.Write(" File Write Operation Starts : ");&lt;br /&gt;m_streamWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),DateTime.Now.ToLongDateString());&lt;br /&gt;m_streamWriter.WriteLine(" ===================================== \n");&lt;br /&gt;m_streamWriter.Flush();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;As you can see from the above code, this code writes some lines to the file.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Now write code on the start and stop button click handlers. As you can see from the following code, the Start button click sets timer's Enabled property as true. Setting timer's Enabled property starts timer to execute the timer event. I set Enabled property as false on the Stop button click event handler, which stops executing the timer tick event.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; button1_Click(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;timer1.Enabled = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; button2_Click(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;timer1.Enabled = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Now&lt;span style="color:#000000;"&gt; last step &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#000000;"&gt;is&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="color:#000000;"&gt; to write timer's&lt;/span&gt; tick event to write current time to the text file. Write the following code on your timer event.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; timer1_Tick(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; sender, System.EventArgs e)&lt;br /&gt;{&lt;br /&gt;m_streamWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),DateTime.Now.ToLongDateString());&lt;br /&gt;m_streamWriter.Flush();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Now use Start and Stop buttons to start and stop the timer. The output mcb.txt file looks like the following figure.&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/mahesh/WorkingwithTimerControlinCSharp11302005054911AM/Images/TimerUpdatedMCB.4.gif" align="bottom" border="0" hspace="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Using Timer control Programmatically&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;If you don't have Visual Studio .NET, you can also write the same sample. Just following these steps.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;&lt;strong&gt;Creating an instance of Timer&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;The Timer class's constructor is used to create a timer object. The constructor is overloaded.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;Public Timer()&lt;br /&gt;Public Timer(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;double&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;) Sets the interval property to the specified.&lt;br /&gt;&lt;br /&gt;Here is&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; how to create a Timer with 5 seconds interval.&lt;br /&gt;&lt;br /&gt;Timer myTimer = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; Timer(500);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Here are some useful members of the Timer class:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt; &lt;/p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;table style="border-collapse: collapse;" bordercolordark="#808080" bordercolorlight="#ffffff" bgcolor="#c0c0c0" border="1" bordercolor="#808080" width="100%"&gt; &lt;tbody&gt;&lt;/tbody&gt;&lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Tick &lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;This event occurs when the Interval has elapsed. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Start&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Starts raising the Tick event by setting Enabled to true. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Stop&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Stops raising the Tick event by setting Enabled to false. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Close&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Releases the resources used by the Timer. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;AutoReset&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Indicates whether the Timer raises the Tick event each time the specified Interval has elapsed or whether the Tick event is raised only once after the first interval has elapsed. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Interval&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Indicates the interval on which to raise the Tick event.&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;Enabled&lt;/span&gt;&lt;/td&gt; &lt;td&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;Indicates whether the Timer raises the Tick event&lt;/span&gt;. &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;span style="font-size:85%;"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;How to use Timer class to raise an event after certain interval?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;timer1.Interval = 5000;&lt;br /&gt;timer1.Enabled = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;timer1.Tick += &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.EventHandler (OnTimerEvent);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Write the event handler&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;This event will be executed after every 5 secs.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; OnTimerEvent(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;object&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; source, EventArgs e)&lt;br /&gt;{&lt;br /&gt;m_streamWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),DateTime.Now.ToLongDateString());&lt;br /&gt;m_streamWriter.Flush();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is originally posted by &lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;a id="ctl00_ContentPlaceHolder1_ArticleFooter1_LinkButtonAuthorName" class="LinkNormalStyle" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ArticleFooter1$LinkButtonAuthorName','')"&gt;Mahesh Chand&lt;/a&gt;&lt;/b&gt; I used this for one of my projects.Hope this will help you all!!!!!&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-6482695130974278305?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/6482695130974278305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=6482695130974278305' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/6482695130974278305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/6482695130974278305'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/05/working-with-timer-control-in-c.html' title='Working with Timer Control in C#'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-3630487521217759503</id><published>2008-05-12T22:36:00.000-07:00</published><updated>2008-05-12T22:42:54.396-07:00</updated><title type='text'>Creating a Windows Service in C#</title><content type='html'>&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; The project name in this sample code is &lt;strong&gt;mcWebService&lt;/strong&gt; which is a spelling mistake. I meant to put &lt;strong&gt;mcWinService&lt;/strong&gt;. And now I don't want to change all the screen shots and code all over again. I hope it won't confuse you :). &lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Ok, its time for one more tutorial. This times pick is Windows Services. Creating Windows Services is not a big deal using C# and Visual Studio. Just follow few simple steps and you are all set to run and test your first Windows Service.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Windows Services is new name for NT Services you used to develop in previous versions of Visual Studio. This tutorial walks you through how to create and use your Windows Services. This Service writes some text to a text file when stop and start the service. The base idea is taken from MSDN but its more elaborated. You can modify it according to your needs.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Step 1. Create Skeleton of the Service&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;To create a new Window Service, pick Windows Service option from your Visual C# Projects, give your service a name, and click OK.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/mahesh/window_service11262005045007AM/Images/win_service10.jpg" align="bottom" border="0" hspace="0" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The result look like this. The Wizard adds WebService1.cs class to your project.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/mahesh/window_service11262005045007AM/Images/win_service11.jpg" align="bottom" border="0" hspace="0" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Set your &lt;strong&gt;ServiceName&lt;/strong&gt; to your own name so it would be easier to recognize your service during testing OR you can set this property programmatically using this line this.ServiceName = "mcWinService";&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;This is the name you will be looking for later :).&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/mahesh/window_service11262005045007AM/Images/window12.jpg" align="bottom" border="0" hspace="0" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The default code of WebService1.cs added by the Wizard looks like here&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;namespace&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; mcWebService&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.Collections;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.Core;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.ComponentModel;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.Configuration;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.Data;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.Web.Services;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.Diagnostics;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.ServiceProcess;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; WinService1 : System.ServiceProcess.ServiceBase&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;&lt;summary&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt; Required designer variable.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;&lt;/summary&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.ComponentModel.Container components;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; WinService1()&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;// This call is required by the WinForms Component Designer. &lt;/span&gt;&lt;span style="font-size:85%;"&gt;InitializeComponent(); &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;// TODO: Add any initialization after the InitComponent call&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;// The main entry point for the process&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; Main()&lt;br /&gt;{&lt;br /&gt;System.ServiceProcess.ServiceBase[] ServicesToRun;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#008000;"&gt;// More than one user Service may run within the same process. To add&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#008000;"&gt;// another service to this process, change the following line to&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#008000;"&gt;/ create a second service object. For example,&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#008000;"&gt;//&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#008000;"&gt;// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new WinService1(), new&lt;br /&gt;ySecondUserService()};&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;ServicesToRun = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.ServiceProcess.ServiceBase[] { &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; WinService1() };&lt;br /&gt;System.ServiceProcess.ServiceBase.Run(ServicesToRun);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;&lt;summary&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt; Required method for Designer support - do not modify&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt; the contents of this method with the code editor.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;&lt;/summary&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;private&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; InitializeComponent()&lt;br /&gt;{&lt;br /&gt;components = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; System.ComponentModel.Container();&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;.ServiceName = "WinService1";&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;&lt;summary&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt; Set things in motion so your service can do its work.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;&lt;/summary&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;protected&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; OnStart(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt;[] args)&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#008000;"&gt;// TODO: Add code here to start your service.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;&lt;summary&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt; Stop this service.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;&lt;/summary&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;protected&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;"&gt; OnStop()&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:85%;color:#008000;"&gt;// TODO: Add code here to perform any tear-down necessary to stop your service.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;Step 2. Add functionality to your service&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;As you saw WebService1.cs, there are two overridden functions OnStart and OnStop. The OnStart function executes when you start your service and the OnStop function gets execute when you stop a service. I write some text to a text file when you start and stop the service. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;protected&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; OnStart(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;[] args)&lt;br /&gt;{&lt;br /&gt;FileStream fs = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; FileStream(@"c:\temp\mcWindowsService.txt" ,&lt;br /&gt;FileMode.OpenOrCreate, FileAccess.Write);&lt;br /&gt;StreamWriter m_streamWriter = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; StreamWriter(fs);&lt;br /&gt;m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);&lt;br /&gt;m_streamWriter.WriteLine(" mcWindowsService: Service Started \n");&lt;br /&gt;m_streamWriter.Flush();&lt;br /&gt;m_streamWriter.Close();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;&lt;summary&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt; Stop this service.&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;///&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#808080;"&gt;&lt;/summary&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;protected&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;override&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; OnStop()&lt;br /&gt;{&lt;br /&gt;FileStream fs = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; FileStream(@"c:\temp\mcWindowsService.txt" ,&lt;br /&gt;FileMode.OpenOrCreate, FileAccess.Write);&lt;br /&gt;StreamWriter m_streamWriter = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt; StreamWriter(fs);&lt;br /&gt;m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);&lt;br /&gt;m_streamWriter.WriteLine(" mcWindowsService: Service Stopped \n"); m_streamWriter.Flush();&lt;br /&gt;m_streamWriter.Close();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;Step 3: Install and Run the Service&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Build of this application makes one exe, mcWinService.exe. You need to call installutil to&lt;br /&gt;egister this service from command line.&lt;br /&gt;installutil C:\mcWebService\bin\Debug\mcWebService.exe&lt;br /&gt;You use /u option to uninstall the service.&lt;br /&gt;installutil /u C:\mcWebService\bin\Debug\mcWebService.exe&lt;br /&gt;Run the application&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Step 4: Start and Stop the Service&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;You need to go to the Computer Management to Start to start and stop the service. You can use Manage menu item by right clicking on My Computer.  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/mahesh/window_service11262005045007AM/Images/window13.gif" align="bottom" border="0" hspace="0" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Under &lt;strong&gt;Services and Applications&lt;/strong&gt;, you will see the service &lt;strong&gt;mcWinService&lt;/strong&gt;. Start and Stop menu item starts and stops the service.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/mahesh/window_service11262005045007AM/Images/window14.jpg" align="bottom" border="0" hspace="0" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;strong&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Step 5: Test the Service&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Go to your temp directory and see if text file is there with contents or not. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;That's it.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;This is originally posted by &lt;/span&gt;&lt;/span&gt;&lt;span class="ArticleDate"&gt; &lt;span class="AuthorName"&gt;                     &lt;a id="ctl00_ContentPlaceHolder1_ArticleHeader1_LinkButtonAuthorName" class="LinkNormalStyle" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ArticleHeader1$LinkButtonAuthorName','')"&gt;Mahesh Chand&lt;/a&gt;  I  used this for one of my projects hope this will be use full for you all!!!&lt;/span&gt;&lt;span id="ctl00_ContentPlaceHolder1_ArticleHeader1_LabelDate"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-3630487521217759503?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/3630487521217759503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=3630487521217759503' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/3630487521217759503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/3630487521217759503'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/05/creating-windows-service-in-c.html' title='Creating a Windows Service in C#'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-1605894565798700239</id><published>2008-03-05T22:13:00.000-08:00</published><updated>2008-03-05T22:16:01.174-08:00</updated><title type='text'>Hidden Skype  Emoticons, Smileys(Sri Lankan Flag)</title><content type='html'>Hi Guys,&lt;br /&gt;&lt;br /&gt;Wanna Show Sri Lankan Flag when you are chatting. Here what you have to do .Type (flag:lk) Thats it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-1605894565798700239?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/1605894565798700239/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=1605894565798700239' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1605894565798700239'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1605894565798700239'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/03/hidden-skype-emoticons-smileyssri.html' title='Hidden Skype  Emoticons, Smileys(Sri Lankan Flag)'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-8337348214103258203</id><published>2008-03-05T21:29:00.000-08:00</published><updated>2008-03-05T21:31:11.541-08:00</updated><title type='text'>Hidden Skype Emoticons, Smileys</title><content type='html'>&lt;p&gt;&lt;strong&gt;Did you know that Skype have hidden emoticons? &lt;/strong&gt;No! Below is a list of the all hidden emoticons that I know and use chatting with my friends.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;How to use hidden emoticons?&lt;/strong&gt; Actually it is pretty simple - you just need to enter the smiley code while chatting with your friends - for example type ‘(drunk)’ to display smiley who have had couple beers :)&lt;/p&gt;&lt;br /&gt;&lt;table id="emoticons" style="border: 2px solid rgb(221, 221, 221); margin: 5px; padding: 5px; background-color: rgb(241, 241, 241); text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Icon&lt;/strong&gt;&lt;/td&gt; &lt;td&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt; &lt;td&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0172-mooning.png" /&gt;&lt;/td&gt; &lt;td&gt;Mooning&lt;/td&gt; &lt;td&gt;&lt;span&gt;(mooning)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0173-middlefinger.png" /&gt;&lt;/td&gt; &lt;td&gt;Finger&lt;/td&gt; &lt;td&gt;&lt;span&gt;(finger)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0174-bandit.png" /&gt;&lt;/td&gt; &lt;td&gt;Bandit&lt;/td&gt; &lt;td&gt;&lt;span&gt;(bandit)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0175-drunk.png" /&gt;&lt;/td&gt; &lt;td&gt;Drunk&lt;/td&gt; &lt;td&gt;&lt;span&gt;(drunk)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0176-smoke.png" /&gt;&lt;/td&gt; &lt;td&gt;Smoking&lt;/td&gt; &lt;td&gt;&lt;span&gt;(smoking)&lt;/span&gt;&lt;span&gt;(smoke)&lt;/span&gt;&lt;span&gt;(ci)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0177-toivo.png" /&gt;&lt;/td&gt; &lt;td&gt;Toivo&lt;/td&gt; &lt;td&gt;&lt;span&gt;(toivo)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0178-rock.png" /&gt;&lt;/td&gt; &lt;td&gt;Rock&lt;/td&gt; &lt;td&gt;&lt;span&gt;(rock)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0179-headbang.png" /&gt;&lt;/td&gt; &lt;td&gt;Headbang&lt;/td&gt; &lt;td&gt;&lt;span&gt;(headbang)&lt;/span&gt;&lt;span&gt;(banghead)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0180-bug.png" /&gt;&lt;/td&gt; &lt;td&gt;Bug&lt;/td&gt; &lt;td&gt;&lt;span&gt;(bug)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0181-fubar.png" /&gt;&lt;/td&gt; &lt;td&gt;Fubar&lt;/td&gt; &lt;td&gt;&lt;span&gt;(fubar)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0182-poolparty.png" /&gt;&lt;/td&gt; &lt;td&gt;Poolparty&lt;/td&gt; &lt;td&gt;&lt;span&gt;(poolparty)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0183-swear.png" /&gt;&lt;/td&gt; &lt;td&gt;Swearing&lt;/td&gt; &lt;td&gt;&lt;span&gt;(swear)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0184-tmi.png" /&gt;&lt;/td&gt; &lt;td&gt;TMI&lt;/td&gt; &lt;td&gt;&lt;span&gt;(tmi)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/emoticon-0185-heidy.png" /&gt;&lt;/td&gt; &lt;td&gt;Heidy&lt;/td&gt; &lt;td&gt;&lt;span&gt;(heidy)&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;img src="http://www.rotorblog.com/wp-content/uploads/skype-emoticons/myspace-emoticon.gif" /&gt;&lt;/td&gt; &lt;td&gt;MySpace (Skype v3.6)&lt;/td&gt; &lt;td&gt;&lt;span&gt;(myspace)&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Skype emoticons (bandit) (drunk) (finger) (headbang) (banghead) (mooning) (rock) (smoking) (smoke) (ci) (toivo) work with &lt;strong&gt;Skype 2.5 and 3.0&lt;/strong&gt;!&lt;/p&gt; Smileys (bug) (fubar) (poolparty) (swear) (tmi)  work only with &lt;strong&gt;Skype 3.0 and up&lt;/strong&gt;!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-8337348214103258203?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/8337348214103258203/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=8337348214103258203' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8337348214103258203'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/8337348214103258203'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/03/hidden-skype-emoticons-smileys.html' title='Hidden Skype Emoticons, Smileys'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-1279312295565973212</id><published>2008-03-05T20:48:00.000-08:00</published><updated>2008-03-05T20:51:49.179-08:00</updated><title type='text'>How to Get "Show Hidden Files and Folders" Back if it is Missing(Edit Registry Another Fix)</title><content type='html'>Start &gt;&gt; Run &gt;&gt; (type) regedit &gt;&gt; (rightclick on the little my computer icon,&lt;br /&gt;and export the whole thing.)&lt;br /&gt;&lt;br /&gt;find this key: HKEY_CURRENT_USER\Software\Microsoft\Windows\&lt;br /&gt;CurrentVersion\Explorer\Advanced. Go to the rightside of the window,&lt;br /&gt;where the values are. Find the value "Hidden" . Rightclick it and modify it to 1.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-1279312295565973212?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/1279312295565973212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=1279312295565973212' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1279312295565973212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1279312295565973212'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/03/how-to-get-show-hidden-files-and_05.html' title='How to Get &quot;Show Hidden Files and Folders&quot; Back if it is Missing(Edit Registry Another Fix)'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-1408462496024153699</id><published>2008-03-05T20:43:00.000-08:00</published><updated>2008-03-05T20:53:20.286-08:00</updated><title type='text'>How to Get "Show Hidden Files and Folders" Back if it is Missing</title><content type='html'>&lt;div class="ArticleHeadline"&gt;If the option to enable "Show Hidden Files and Folders" is MISSING from your Folders Options &gt; View &gt; Advanced Settings, find this key in your registry:&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows&lt;br /&gt;\CurrentVersion\Explorer\Advanced\Folder\Hidden]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Modify the string value "Type" and enter "group" as value data.&lt;br /&gt;&lt;br /&gt;After the edit is complete hit F5 to refresh, and go look in your Folder Options.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-1408462496024153699?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/1408462496024153699/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=1408462496024153699' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1408462496024153699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/1408462496024153699'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/03/how-to-get-show-hidden-files-and.html' title='How to Get &quot;Show Hidden Files and Folders&quot; Back if it is Missing'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-6695652804411584581</id><published>2008-02-27T22:36:00.000-08:00</published><updated>2008-02-27T22:37:55.692-08:00</updated><title type='text'>USB Drive AutoRun.inf Tweaking</title><content type='html'>The &lt;em&gt;autorun.inf&lt;/em&gt; file is the key to getting your &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive (or CD-ROM drive, for that matter) to perform certain actions automatically and customize it’s look in &lt;em&gt;My Computer&lt;/em&gt;.  The purpose of this article is to shed some light on how this can be done. &lt;h2&gt;&lt;em&gt;Autorun.inf&lt;/em&gt; Structure&lt;/h2&gt; &lt;p&gt;The &lt;em&gt;autorun.inf &lt;/em&gt;file is a simple text file that can be opened up in any text editor (e.g. notepad).  It always starts with a section header of:&lt;/p&gt; &lt;p&gt;&lt;code&gt;[autorun]&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Below this header is a list of different options.  Each of these options is in the following format:&lt;/p&gt; &lt;p&gt;&lt;code&gt;option=value&lt;/code&gt;&lt;/p&gt; &lt;div style="text-align: center;"&gt;&lt;script type="text/javascript"&gt;&lt;!-- google_ad_client = "pub-7950906854594110"; google_alternate_color = "FFFFFF"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "text_image"; google_ad_channel ="Injected"; google_color_border = "FFFFFF"; google_color_link = "909D73"; google_color_bg = "FFFFFF"; google_color_text = "000000"; google_color_url = "909D73"; //--&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt; &lt;/script&gt;&lt;/div&gt;&lt;p&gt;where&lt;/p&gt; &lt;p&gt;&lt;code&gt;option&lt;/code&gt; is the option that you want to set and &lt;code&gt;value&lt;/code&gt; is the value that you are setting for that option.  So, if you had an option &lt;em&gt;foo&lt;/em&gt; and you wanted to be set to &lt;em&gt;bar&lt;/em&gt;, then you would enter:&lt;/p&gt; &lt;p&gt;&lt;code&gt;foo=bar&lt;/code&gt;&lt;/p&gt; &lt;p&gt;(Do not use &lt;code&gt;foo=bar&lt;/code&gt; in your &lt;em&gt;autorun.inf&lt;/em&gt; file as it is only an example, not a real option setting.)&lt;/p&gt; &lt;p&gt;That is all there really is to understand about the structure of an &lt;em&gt;autorun.inf&lt;/em&gt; file.  On to doing some actual cool stuff with it!&lt;/p&gt; &lt;h2&gt;Setting a Custom Icon&lt;/h2&gt; &lt;p&gt;To create a custom icon for your &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive, use the &lt;code&gt;icon&lt;/code&gt; option.  Set it to the name of the icon file.&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;Note: Since drive letters can change for &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drives, the file path is relative to the root of the drive.  This means that if your &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive is presently mounted on &lt;em&gt;U:&lt;/em&gt; and your icon is located at &lt;em&gt;U:\Icons\MyIcon.ico&lt;/em&gt;, then you would enter &lt;em&gt;\Icons\MyIcon.ico&lt;/em&gt; for the value of this option.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;For example, if you had an icon on the root of the &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive called &lt;em&gt;coffeecup.ico&lt;/em&gt; and you wanted this to be the icon that showed up for the &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive, you would enter:&lt;/p&gt; &lt;p&gt;&lt;code&gt;icon=coffeecup.ico&lt;/code&gt;&lt;/p&gt; &lt;p&gt;You are not limited to .ico files. If, for example, you have an executable with a nice icon, you can specify it as the icon file. For example:&lt;/p&gt; &lt;p&gt;&lt;code&gt;icon=DCoTopen.exe&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This is valid as long as &lt;em&gt;DCoTopen.exe&lt;/em&gt; is available on the root of the &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive.&lt;/p&gt; &lt;p&gt;Some files have more than one icon embedded in them. If this is the case, you can select which icon to use by specifing the index number after the file name. For example:&lt;/p&gt; &lt;p&gt;&lt;code&gt;icon=iconlib.dll,2&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This will use the second icon in the &lt;em&gt;iconlib.dll&lt;/em&gt; file.&lt;/p&gt; &lt;h2&gt;Naming Your &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; Drive&lt;/h2&gt; &lt;p&gt;If you would like your &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive to display a specific name othr than the drive label created when it is formatted, use the &lt;code&gt;label&lt;/code&gt; option.  For example, if I wanted to call my drive &lt;em&gt;DCoT Drive&lt;/em&gt;, I would add this to my &lt;em&gt;autorun.inf&lt;/em&gt; file:&lt;/p&gt; &lt;p&gt;&lt;code&gt;label=DCoT Drive&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Now, when you look at your &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive in &lt;em&gt;My Computer&lt;/em&gt;, it will say &lt;em&gt;DCoT Drive&lt;/em&gt; by the drive letter.&lt;/p&gt; &lt;h2&gt;Setting AutoPlay Options&lt;/h2&gt; &lt;p&gt;&lt;em&gt;AutoPlay&lt;/em&gt; is a relatively new function of &lt;a href="http://www.dailycupoftech.com/category/Windows"&gt;Windows&lt;/a&gt; XP.  It allows you to set up what file is run when the &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive is plugged into the computer and the message that you are prompted with. There are two options that work in conjunction with AutoPlay. The first is &lt;code&gt;open&lt;/code&gt;.  It specifies the program that you can run automatically with AutoPlay.  So, if we wanted to run a program called &lt;em&gt;DCoTopen.exe&lt;/em&gt;, you would add the this to your &lt;em&gt;autorun.inf&lt;/em&gt; file:&lt;/p&gt; &lt;p&gt;&lt;code&gt;open=DCoTopen.exe&lt;/code&gt;&lt;/p&gt; &lt;p&gt;The second option that we add is the message the user is prompted with.  To set this, we use the &lt;code&gt;action&lt;/code&gt; option.  If we want the message to say &lt;em&gt;DCoT Open Program&lt;/em&gt;, add the following to &lt;em&gt;autorun.inf&lt;/em&gt;:&lt;/p&gt; &lt;p&gt;&lt;code&gt;action=DCoT Open Program&lt;/code&gt;&lt;/p&gt; &lt;p&gt;Once you have added this information, AutoPlay should look something like this:&lt;/p&gt; &lt;center&gt;&lt;img src="http://www.dailycupoftech.com/wp-content/uploads/2006/09/screencapture004.png" id="image152" alt="AutoPlay" /&gt;&lt;/center&gt; &lt;h2&gt;Adding Context Menu Items&lt;/h2&gt; &lt;p&gt;There are certain basic options such as &lt;em&gt;Open&lt;/em&gt; and &lt;em&gt;Explore&lt;/em&gt; that are available when you right click on a &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive.  But, wouldn’t it be cool to add your own?  You can using a couple of lines in the &lt;em&gt;autorun.inf&lt;/em&gt; file.&lt;/p&gt; &lt;p&gt;The first thing that we need to do is create an action, give it a name, and a message.  We do all of this using the &lt;code&gt;shell\&lt;em&gt;verb&lt;/em&gt;&lt;/code&gt; option.  For example, let’s say that we would like to create an action called &lt;em&gt;lost&lt;/em&gt;.  It does not matter what the actin is called.  It can be anything you want.  We would also like to show the message &lt;em&gt;Help! I’m Lost!&lt;/em&gt; in the context menu.  We would simply add this line to &lt;em&gt;autorun.inf&lt;/em&gt;:&lt;/p&gt; &lt;p&gt;&lt;code&gt;shell\lost=Help! I'm Lost!&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This will display &lt;em&gt;Help! I’m Lost!&lt;/em&gt; in the context menu so that you can click on it. But, it doesn’t know what to do when you click on it. Tell the system by using &lt;code&gt;shell\&lt;em&gt;verb&lt;/em&gt;\command&lt;/code&gt; option.  In our example, we want to run the &lt;em&gt;Lost.exe&lt;/em&gt; application.  Adding this line will do the trick:&lt;/p&gt; &lt;p&gt;&lt;code&gt;shell\lost\command=Lost.exe&lt;/code&gt;&lt;/p&gt; &lt;p&gt;You can add as many of these line pairs as you want to make the context menu as custom as you want.&lt;/p&gt; &lt;h2&gt;Changing Default Action&lt;/h2&gt; &lt;p&gt;When you double click on your &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive, by default it will open up the drive so that you can browse through the files. Often, it is advantageous to perform some other action when the user double clicks the &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive icon.  You do this with the &lt;code&gt;shell&lt;/code&gt; option.  If we wanted to run the &lt;em&gt;Lost.exe&lt;/em&gt; program from the previous section automatically when we double clicked on the &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive, we would add this line:&lt;/p&gt; &lt;p&gt;&lt;code&gt;shell=lost&lt;/code&gt;&lt;/p&gt; &lt;p&gt;because &lt;em&gt;lost&lt;/em&gt; is the name of the action that was specified in the earlier lines.&lt;/p&gt; &lt;h2&gt;Viewing a File&lt;/h2&gt; &lt;p&gt;If you wanted to view a file on your &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive in the default application instead of running a program on the drive, you can substitute the &lt;code&gt;open&lt;/code&gt; option for the &lt;code&gt;shellexecute&lt;/code&gt; option.  For example, if you wanted to open up a website called, oh, I don’t know, say &lt;em&gt;http://www.DailyCupOfTech.com&lt;/em&gt; in the default web browser, you could user the following:&lt;/p&gt; &lt;p&gt;&lt;code&gt;shellexecute=http://www.DailyCupOfTech.com&lt;/code&gt;&lt;/p&gt; &lt;p&gt;This will work for any file.  This is the equivalent of using &lt;em&gt;Start - Run…&lt;/em&gt; and then typing in a file name and clicking &lt;em&gt;OK&lt;/em&gt;.&lt;/p&gt; &lt;h2&gt;School’s Out, Time To Play!&lt;/h2&gt; &lt;p&gt;That is about all there is to customizing the &lt;em&gt;autorun.ing&lt;/em&gt; file.  Now that you know what you are doing, it’s time to start playing!  I have created the &lt;a href="http://dailycupoftech.com/Downloads/AutorunDabblerToolkit.zip" id="p153" title="Autorun Dabbler's Toolkit"&gt;Autorun Dabbler’s Toolkit&lt;/a&gt; that you can play with.&lt;/p&gt; &lt;p&gt;Download the zip file and extract the contents to the root of an empty &lt;a href="http://www.dailycupoftech.com/category/USB"&gt;USB&lt;/a&gt; drive. You can now edit the &lt;em&gt;autorun.inf&lt;/em&gt; and get it to do different things.  Have fun! &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-6695652804411584581?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/6695652804411584581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=6695652804411584581' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/6695652804411584581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/6695652804411584581'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/02/usb-drive-autoruninf-tweaking.html' title='USB Drive AutoRun.inf Tweaking'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2027769947859867205.post-6231198894589187087</id><published>2008-02-26T23:34:00.000-08:00</published><updated>2008-02-26T23:47:52.044-08:00</updated><title type='text'>Speed Up Your PC</title><content type='html'>&lt;h1&gt;5 ways to speed up your PC&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;By following a few simple guidelines, you can maintain your computer and keep it running smoothly. This article discusses how to use the tools available in Windows XP Service Pack 2 (SP2) and Windows Vista to more efficiently maintain your computer and safeguard your privacy when you're online.&lt;/p&gt;&lt;h5 style="padding-top: 2px;"&gt;On This Page&lt;/h5&gt;&lt;a name="EQB"&gt;&lt;/a&gt;&lt;h2&gt;Free up disk space&lt;/h2&gt;&lt;p&gt;By freeing disk space, you can improve the performance of your computer. The Disk Cleanup tool helps you free up space on your hard disk. The utility identifies files that you can safely delete, and then enables you to choose whether you want to delete some or all of the identified files.&lt;br /&gt;Use Disk Cleanup to:&lt;/p&gt;&lt;table border="0" cellpadding="0" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="listBullet" valign="top"&gt;•&lt;/td&gt;&lt;td class="listItem"&gt;&lt;p&gt;Remove temporary Internet files.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="listBullet" valign="top"&gt;•&lt;/td&gt;&lt;td class="listItem"&gt;&lt;p&gt;Remove downloaded program files (such as Microsoft ActiveX controls and Java applets).&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="listBullet" valign="top"&gt;•&lt;/td&gt;&lt;td class="listItem"&gt;&lt;p&gt;Empty the Recycle Bin.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="listBullet" valign="top"&gt;•&lt;/td&gt;&lt;td class="listItem"&gt;&lt;p&gt;Remove Windows temporary files.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="listBullet" valign="top"&gt;•&lt;/td&gt;&lt;td class="listItem"&gt;&lt;p&gt;Remove optional Windows components that you don't use.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="listBullet" valign="top"&gt;•&lt;/td&gt;&lt;td class="listItem"&gt;&lt;p&gt;Remove installed programs that you no longer use.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;b&gt;Tip:&lt;/b&gt; Typically, temporary Internet files take the most amount of space because the browser caches each page you visit for faster access later.&lt;/p&gt;&lt;p&gt;&lt;b&gt;To use Disk Cleanup&lt;/b&gt;&lt;/p&gt;&lt;table class="numberedList" border="0" cellpadding="0" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;1.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Click &lt;b&gt;Start&lt;/b&gt;, point to &lt;b&gt;All Programs&lt;/b&gt;, point to &lt;b&gt;Accessories&lt;/b&gt;, point to &lt;b&gt;System Tools&lt;/b&gt;, and then click &lt;b&gt;Disk Cleanup&lt;/b&gt;. If several drives are available, you might be prompted to specify which drive you want to clean.&lt;/p&gt;&lt;p&gt;&lt;img src="http://www.microsoft.com/library/media/1033/atwork/images/gettingstarted/diskcleanup1.jpg" alt="Image of Disk Cleanup dialog box" border="0" height="128" width="300" /&gt;&lt;br /&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;2.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;In the &lt;b&gt;Disk Cleanup for&lt;/b&gt; dialog box, scroll through the content of the &lt;b&gt;Files to delete&lt;/b&gt; list.&lt;/p&gt;&lt;div style="width: 300px;"&gt;&lt;img src="http://www.microsoft.com/library/media/1033/atwork/images/gettingstarted/diskcleanup2.jpg" alt="Image of Disk Cleanup for dialog box" border="0" height="356" width="300" /&gt;&lt;br /&gt;&lt;p class="figureCaption"&gt;Choose the files that you want to delete.&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;3.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Clear the check boxes for files that you don't want to delete, and then click &lt;b&gt;OK&lt;/b&gt;.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;4.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;When prompted to confirm that you want to delete the specified files, click &lt;b&gt;Yes&lt;/b&gt;.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;After a few minutes, the process completes and the Disk Cleanup dialog box closes, leaving your computer cleaner and performing better.&lt;/p&gt;&lt;a name="E6D"&gt;&lt;/a&gt;&lt;h2&gt;Speed up access to data&lt;/h2&gt;&lt;p&gt;Disk fragmentation slows the overall performance of your system. When files are fragmented, the computer must search the hard disk when the file is opened to piece it back together. The response time can be significantly longer.&lt;/p&gt;&lt;p&gt;Disk Defragmenter is a Windows utility that consolidates fragmented files and folders on your computer's hard disk so that each occupies a single space on the disk. With your files stored neatly end-to-end, without fragmentation, reading and writing to the disk speeds up.&lt;/p&gt;&lt;p&gt;&lt;b&gt;When to run Disk Defragmenter&lt;/b&gt;&lt;br /&gt;In addition to running Disk Defragmenter at regular intervals—monthly is optimal—there are other times you should run it too, such as when:&lt;/p&gt;&lt;table border="0" cellpadding="0" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="listBullet" valign="top"&gt;•&lt;/td&gt;&lt;td class="listItem"&gt;&lt;p&gt;You add a large number of files.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="listBullet" valign="top"&gt;•&lt;/td&gt;&lt;td class="listItem"&gt;&lt;p&gt;Your free disk space totals 15 percent or less.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="listBullet" valign="top"&gt;•&lt;/td&gt;&lt;td class="listItem"&gt;&lt;p&gt;You install new programs or a new version of Windows.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;b&gt;To use Disk Defragmenter:&lt;/b&gt;&lt;/p&gt;&lt;table class="numberedList" border="0" cellpadding="0" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;1.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Click &lt;b&gt;Start&lt;/b&gt;, point to &lt;b&gt;All Programs&lt;/b&gt;, point to &lt;b&gt;Accessories&lt;/b&gt;, point to &lt;b&gt;System Tools&lt;/b&gt;, and then click &lt;b&gt;Disk Defragmenter&lt;/b&gt;.&lt;/p&gt;&lt;div style="width: 325px;"&gt;&lt;img src="http://www.microsoft.com/library/media/1033/atwork/images/gettingstarted/diskdefragmenter1.jpg" alt="Image of the Disk Defragmenter dialog box" border="0" height="238" width="325" /&gt;&lt;br /&gt;&lt;p class="figureCaption"&gt;Click Analyze to start the Disk Defragmenter.&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;2.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;In the &lt;b&gt;Disk Defragmenter&lt;/b&gt; dialog box, click the drives that you want to defragment, and then click the &lt;b&gt;Analyze&lt;/b&gt; button. After the disk is analyzed, a dialog box appears, letting you know whether you should defragment the analyzed drives.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Tip:&lt;/b&gt; You should analyze a volume before defragmenting it to get an estimate of how long the defragmentation process will take.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;3.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;To defragment the selected drive or drives, click the &lt;b&gt;Defragment&lt;/b&gt; button. Note: In Windows Vista, there is no graphical user interface to demonstrate the progress—but your hard drive is still being defragmented.&lt;/p&gt;&lt;p&gt;After the defragmentation is complete, Disk Defragmenter displays the results.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;4.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;To display detailed information about the defragmented disk or partition, click &lt;b&gt;View Report&lt;/b&gt;.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;5.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;To close the &lt;b&gt;View Report&lt;/b&gt; dialog box, click &lt;b&gt;Close&lt;/b&gt;.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;6.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;To close the Disk Defragmenter utility, click the &lt;b&gt;Close&lt;/b&gt; button on the title bar of the window.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;a name="EVG"&gt;&lt;/a&gt;&lt;h2&gt;Detect and repair disk errors&lt;/h2&gt;&lt;p&gt;In addition to running Disk Cleanup and Disk Defragmenter to optimize the performance of your computer, you can check the integrity of the files stored on your hard disk by running the Error Checking utility.&lt;/p&gt;&lt;p&gt;As you use your hard drive, it can develop bad sectors. Bad sectors slow down hard disk performance and sometimes make data writing (such as file saving) difficult, or even impossible. The Error Checking utility scans the hard drive for bad sectors, and scans for file system errors to see whether certain files or folders are misplaced.&lt;/p&gt;&lt;p&gt;If you use your computer daily, you should run this utility once a week to help prevent data loss.&lt;/p&gt;&lt;p&gt;&lt;b&gt;To run the Error Checking utility:&lt;/b&gt;&lt;/p&gt;&lt;table class="numberedList" border="0" cellpadding="0" cellspacing="0"&gt;&lt;tbody&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;1.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Close all open files.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;2.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Click &lt;b&gt;Start&lt;/b&gt;, and then click &lt;b&gt;My Computer&lt;/b&gt;.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;3.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;In the My Computer window, right-click the hard disk you want to search for bad sectors, and then click &lt;b&gt;Properties&lt;/b&gt;.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;4.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;In the &lt;b&gt;Properties&lt;/b&gt; dialog box, click the &lt;b&gt;Tools&lt;/b&gt; tab.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;5.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;Click the &lt;b&gt;Check Now&lt;/b&gt; button.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;6.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;In the &lt;b&gt;Check Disk&lt;/b&gt; dialog box, select the &lt;b&gt;Scan for and attempt recovery of bad sectors&lt;/b&gt; check box, and then click &lt;b&gt;Start&lt;/b&gt;.&lt;/p&gt;&lt;p&gt;&lt;img src="http://www.microsoft.com/library/media/1033/atwork/images/gettingstarted/checkdisk.jpg" alt="Image of Check Disk dialog box" border="0" height="219" width="284" /&gt;&lt;br /&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td class="listNumber" align="right" nowrap="nowrap"&gt;&lt;p&gt;7.&lt;/p&gt;&lt;/td&gt;&lt;td&gt;&lt;p&gt;If bad sectors are found, choose to fix them.&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p&gt;&lt;b&gt;Tip:&lt;/b&gt; Only select the "Automatically fix file system errors" check box if you think that your disk contains bad sectors.&lt;/p&gt;&lt;a name="EXAAC"&gt;&lt;/a&gt;&lt;h2&gt;Protect your computer against spyware&lt;/h2&gt;&lt;p&gt;Spyware collects personal information without letting you know and without asking for permission. From the Web sites you visit to usernames and passwords, spyware can put you and your confidential information at risk. In addition to privacy concerns, spyware can hamper your computer's performance. To combat spyware, you might want to consider using Microsoft Windows Defender, which is &lt;a href="http://www.microsoft.com/protect/computer/spyware/vista.mspx"&gt;included in Windows Vista&lt;/a&gt;, and is available as a &lt;a href="http://www.microsoft.com/athome/security/spyware/software/default.mspx"&gt;free download for Microsoft XP SP2&lt;/a&gt;. Alternatively, there are other free anti-spyware software programs available.&lt;/p&gt;&lt;a name="EDBAC"&gt;&lt;/a&gt;&lt;h2&gt;Learn all about ReadyBoost&lt;/h2&gt;&lt;p&gt;If you're using Windows Vista, you can use ReadyBoost to speed up your system. A new concept in adding memory to a system, it allows you to use non-volatile flash memory—like a USB flash drive or a memory card—to improve performance without having to add additional memory. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;This articl is From Microsoft.&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2027769947859867205-6231198894589187087?l=iroshan29.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iroshan29.blogspot.com/feeds/6231198894589187087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2027769947859867205&amp;postID=6231198894589187087' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/6231198894589187087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2027769947859867205/posts/default/6231198894589187087'/><link rel='alternate' type='text/html' href='http://iroshan29.blogspot.com/2008/02/speed-up-your-pc.html' title='Speed Up Your PC'/><author><name>Iroshan</name><uri>http://www.blogger.com/profile/08649586997722013898</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>
