Friday, 30 January 2009
Failed to access IIS metabase error when running IIS Server with ASP.Net
SQL Create stored procedure script with error handling
USE [MyDatabase]GOPRINT 'DROP PROCEDURE [usp_mysproc]'GOif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_mysproc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[usp_mysproc]GOPRINT 'CREATE PROCEDURE [usp_mysproc]'GOCREATE PROCEDURE [dbo].[usp_mysproc]ASBEGIN TRANDECLARE @errorNo int, @rowCount int, @errorStr varchar(4000)DELETE FROM Table1 Where SampleDate < getdate()SELECT @errorNo = @@ERROR, @rowCount = @@ROWCOUNTIF @errorNo <> 0 BEGINSET @errorStr = 'Error deleting old load records "load_Master"'GOTO ErrHandlerENDCOMMITRETURN 0ErrHandler:ROLLBACKDECLARE @procName sysnameSELECT @procName = object_name( @@procid ), @errorStr = ISNULL( @errorStr, 'Unknown error' )IF @errorNo <> 0 BEGINSELECT @errorStr = @errorStr + ': procedure=%s, error=%i'RAISERROR( @errorStr, 16, 1, @procName, @errorNo )ENDELSE BEGINSELECT @errorStr = @errorStr + ': procedure=%s'RAISERROR( @errorStr, 16, 1, @procName )ENDRETURN 1GOGRANT EXECUTE ON [dbo].[usp_mysproc] TO [MyDatabaseEditor]GOGRANT EXECUTE ON [dbo].[usp_mysproc] TO [MyDatabaseAdmin]GO
Useful SQL Server security stored procedures
Returns information about the members of a role in the current database.
exec sp_helprolemember
Returns information about user permissions for an object in the current database.
exec sp_helprotect [Table/View/Procedure]
Returns information about the roles in the current database.
exec sp_helprole
For more info check Microsoft MSDN page.
Thursday, 29 January 2009
SQL delete with join
SQL Case statement
Friday, 23 January 2009
Bloomberg Help
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..)
Thursday, 22 January 2009
Copy data from one table to another based on mulitple joins
Insert data to database and get generated key back
Sample table with identity column.
CREATE TABLE [dbo].[Table1]([Id] int IDENTITY(1,1) NOT NULL,[Value] [varchar](10) NOT NULL,CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED([Id] ASC))
C# code than inserts data to database and gets generated id back.
class TestInsertDao : AdoDaoSupport
{private string insertSql = @"INSERT INTO Table1(Value)VALUES(@Value)SET @Id = SCOPE_IDENTITY()";public TestInsertDao(IDbProvider dbProvider)
{this.DbProvider = dbProvider;
}public int Insert(string value){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
Friday, 16 January 2009
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 one
Sp_who2
Run this command to get the SQL for a SPID
DBCC INPUTBUFFER (<SPID>)
Run this command to get more info about the lock
EXEC SP_LOCK <SPID>
Monday, 12 January 2009
C# overloading index operator
class MyClass
{private readonly Dictionary<string,object> data = new Dictionary<string,object>();public object this [string index]{set{ data[index] = value; }get{ return data[index]; }}public static void 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, } }
Friday, 9 January 2009
c# directory separator character
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
AppDomain.CurrentDomain.BaseDirectory
Wednesday, 7 January 2009
Open command line window in windows XP from the context menu
This works only for x86 system, to add context menu item to x64 machine follow these steps.
Tuesday, 6 January 2009
ASP.NET vs. J2EE Discussion
Friday, 2 January 2009
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><section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /></configSections><log4net><appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"><param name="File" value="Log\\MyProject.log" /><param name="AppendToFile" value="true" /><param name="RollingStyle" value="Size" /><param name="MaxSizeRollBackups" value="10" /><param name="MaximumFileSize" value="500KB" /><param name="StaticLogFileName" value="true" /><param name="Threshold" value="INFO"/><layout type="log4net.Layout.PatternLayout"><param name="ConversionPattern" value="%d [%t] %-5p %c.%M():%L - %m%n" /></layout></appender><appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"><param name="Threshold" value="DEBUG"/><layout type="log4net.Layout.PatternLayout"><conversionPattern value="%d [%t] %-5p %c.%M():%L - %m%n" /></layout></appender><logger name="MyCompany"><appender-ref ref="RollingFileAppender" /><appender-ref ref="ConsoleAppender" /></logger></log4net></configuration>
Please make sure than <logger name="MyCompany"> is the same as your project namespace. - Add the following line to AssemblyInfo.cs to execute log4net configuration
[assembly: log4net.Config.XmlConfigurator()]
Test Program
public class Program{static private readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);static void Main(string[] args){log.Info("test");
}}
C# allowing Unit Test project to access internal members of another project
MySolution + MyProject + MyProjectTestAdd the following line to AssemblyInfo.cs in MyProject
[assembly: InternalsVisibleTo("MyProjectTest")]This will allow you to access internal classes from MyProjectTest(unittests) project