Posts

Showing posts from January, 2009

Failed to access IIS metabase error when running IIS Server with ASP.Net

This is happening when you install IIS after .Net 2.0 Framework. Just reinstall Asp.Net. c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -i

SQL Create stored procedure script with error handling

Click here to see improved version of this script using try/catch syntax USE [MyDatabase] GOPRINT 'DROP PROCEDURE [usp_mysproc]' GOifexists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_mysproc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1) dropprocedure [dbo].[usp_mysproc] GOPRINT 'CREATE PROCEDURE [usp_mysproc]' GOCREATEPROCEDURE [dbo].[usp_mysproc] ASBEGINTRANDECLARE @errorNo int, @rowCountint, @errorStr varchar(4000) DELETEFROMTable1 Where SampleDate < getdate() SELECT @errorNo = @@ERROR, @

Useful SQL Server security stored procedures

Returns information about the members of a role in the current database.execsp_helprolememberReturns information about user permissions for an object in the current database.execsp_helprotect [Table/View/Procedure]Returns information about the roles in the current database.execsp_helproleFor more info check Microsoft MSDN page.

SQL delete with join

This statement deletes data from Table1. This is useful if you have a join with multiple tables or multiple columns. DELETETable1 FROMTable1 t1 JOINTable2 t2 ON t1.Id1 = t2.Id1 AND t1.Id2 = t2.Id2

SQL Case statement

Bloomberg Help

GP - price/volume graph
G - graph templates
HP - historical prices
CFTC - commodity futures traders commitment
BLP - bloomberg launchpad
IAM - user information
FLDS - field finder
FPRP - field info (older)
ALT-D - terminal defaults
ALT-L - list bloomberg keys
PRTL - Client Services Portal (submit a query, technical docs)
CACS - Corporate Action Calendar
POSH - Bloomberg Marketplace (cars etc..)

Copy data from one table to another based on mulitple joins

This sample shows how to copy data from table A to table B based on multiple join columns. INSERTINTO B(Value1, Value2) SELECTDISTINCTValue1, Value2 FROM A t1 WHERENOTEXISTS(SELECT 1 FROM B t2 WHERE t1.Value1 = t2.Value1 AND t1.Value2 = t2.Value2)

Insert data to database and get generated key back

Sample table with identity column.CREATETABLE [dbo].[Table1]( [Id] intIDENTITY(1,1) NOTNULL, [Value] [varchar](10) NOTNULL, CONSTRAINT [PK_Table1] PRIMARYKEYCLUSTERED ( [Id] ASC ) )C# code than inserts data to database and gets generated id back. class TestInsertDao : AdoDaoSupport { privatestring insertSql = @"INSERT INTO Table1(Value) VALUES(@Value) SET @Id = SCOPE_IDENTITY() "; public TestInsertDao(IDbProvider dbProvider) { this.DbProvider = dbProvider; } publicint Insert(stringvalue) { IDbParameters parameters = CreateDbParameters(); parameters.Add("Value", DbType.String).Value = value; parameters.AddOut("Id", DbType.Int32); AdoTemplate.ExecuteNonQuery(CommandType.Text, deleteSql, parameters); return (int)parameters["@Id"].Value; } } To get more info on C# spring setup refer to this post Using Spring.NET to load data to DataTable

C# Create Guid

This is a short form 32 characters GUID System.Guid.NewGuid().ToString("N")

SQL Server monitoring rogue processes

Run one of these queries to check if there are any SPIDs with Blocked Status or High CPU time. It also shows the hostname, loginname, logintime info.SELECT * FROM sys.sysprocesses -- or this oneSp_who2 Run this command to get the SQL for a SPIDDBCC INPUTBUFFER (<SPID>)Run this command to get more info about the lockEXECSP_LOCK <SPID>

C# overloading index operator

class MyClass { privatereadonly Dictionary<string,object> data = new Dictionary<string,object>(); publicobjectthis [string index] { set{ data[index] = value; } get{ return data[index]; } } publicstaticvoid Main() { MyClass me = new MyClass(); me["test"] = "sample value"; Console.WriteLine(me["test"]); } }

C# params keyword

public class MyClass { public static void UseParams(params int[] list) { for ( int i = 0 ; i < list.Length ; i++ ) { Console.Write(string.format("{0},",list[i])); } } public static void Main() { UseParams(1); //1, UseParams(1,2,3); //1,2,3, } }

c# directory separator character

Directory separator character can be found in Path class. Console.WriteLine("Path.AltDirectorySeparatorChar={0}", Path.AltDirectorySeparatorChar) Console.WriteLine("Path.DirectorySeparatorChar={0}", Path.DirectorySeparatorChar) Console.WriteLine("Path.PathSeparator={0}", Path.PathSeparator) Console.WriteLine("Path.VolumeSeparatorChar={0}", Path.VolumeSeparatorChar) ' Path.AltDirectorySeparatorChar=/ ' Path.DirectorySeparatorChar=\ ' Path.PathSeparator=; ' Path.VolumeSeparatorChar=:

C# get application directory path

To find the application directory (were exe file is) during runtime use this: AppDomain.CurrentDomain.BaseDirectory

ASP .NET Charting Control

SctottGu's Blog about the new ASP.NET 3.5 Charting Control

Open command line window in windows XP from the context menu

This is a very useful tool for Windows XP that enables to you open command line window from context menu. Just right click on any folder and select Open Command Window Here. You can download it from the PowerToys Windows XP page.
This works only for x86 system, to add context menu item to x64 machine follow these steps.

ASP.NET vs. J2EE Discussion

I think this page has a decent discussion about pros and cons of both technologies.

C# Log4Net configuration

- Add referece to log4net.dll file - Add log4net configuration to App.config file  <?xml version="1.0" encoding="utf-8" ?><configuration><configSections><sectionname="log4net"type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/></configSections><log4net><appendername="RollingFileAppender"type="log4net.Appender.RollingFileAppender"><paramname="File"value="Log\\MyProject.log"/><paramname="AppendToFile"value="true"/><paramname="RollingStyle"value="Size"/><paramname="MaxSizeRollBackups"value="10"/><paramname="MaximumFileSize"value="500KB"/><paramname="StaticLogFileName"value="true"/><paramname="Threshold"value="INFO"/><layouttype="log4net.Layout.PatternLayout"><paramname="C…

C# allowing Unit Test project to access internal members of another project

Assuming that you have 2 projects in your solution MySolution + MyProject + MyProjectTest Add the following line to AssemblyInfo.cs in MyProject [assembly: InternalsVisibleTo("MyProjectTest")] This will allow you to access internal classes from MyProjectTest(unittests) project