Thursday, September 22, 2011

How to Monitor a Directory for Changes in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplicationTest
{
class Program
{
static void Main(string[] args)
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"c:\";
watcher.Renamed += new RenamedEventHandler(watcher_Renamed);
watcher.EnableRaisingEvents = true;
Console.ReadLine();
}

static void watcher_Renamed(object sender, RenamedEventArgs e)
{
Console.WriteLine("Renamed from {0} to {1}", e.OldFullPath, e.FullPath);
}
}

}

Sunday, September 4, 2011

Find a procedures having a particular text to be searched in.

SELECT ob.id,ob.name
FROM sys.sysobjects AS ob INNER JOIN
sys.syscomments AS comm ON ob.id = comm.id
where ob.xtype='P' and ob.uid=1 and comm.text like '%(list%'

Object counts in SQL server Database

select
case xtype
when 'D' then 'Default Constraint'
when 'F' then 'Foreign Key Constraint'
when 'FN' then 'Function(s)'
when 'P' then 'Stored Procedure'
when 'PK' then 'Primary Key Constraint'
when 'SQ' then 'SQ'
when 'U' then 'User defined table'
when 'UQ' then 'Unique Constraint'
Else 'Other'
end Object_nm,
count(1) cnt
from dbo.sysobjects
where UID=1
group by xtype order by cnt desc