Posts

Multiple TeamCity Build Agents on one Server

multiple-teamcity-build-agents-on-one-server

How to recalculate Excel named range when another named range changes

Sbt template to setup scala multi-project build with dependencies

GitHub project 'sbt-multiproject-template'

SQL Server User-Defined Table Type

Scala Option Type

The Neophyte's Guide to Scala Part 5: The Option Type by Daniel Westheide

SQL Server Isolation Levels By Example

SQL Server Isolation Levels By Example

SQL Server refresh all views & stored procedures

Scala Play Framework json case class example

The simplest Node (with Connect) html server

How to enable Kerberos Delegation in Google Chrome

* Using Registry Key Set/Add this string registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome] Name: AuthNegotiateDelegateWhitelist Value: * * Using Command Line param --auth-negotiate-delegate-whitelist=* Delegation can be restricted to servers in the specific domain *.mydomain.com I’ve tested it with IIS + SQL Server and double hop delegation works fine. You can read more about Google Chrome command line params here .

Remote debugging IIS Web Application from Visual Studio

Setup your debug environment as described in Remote debugging from Visual Studio post. When you click ‘Attach’ select w3wp.exe process. If you’re running Application Pools with multiple version of .Net you might see more than one process so make sure you select the correct one.

DelegConfig Kerberos Delegation Configuration Reporting Tool by Brian Murphy-Booth

DelegConfig is an ASP.Net application to test Kerberos/Delegation configuration on your IIS & SQL Server. Useful for testing double hop authentication issues.

IIS Windows Authentication/Delegation issue with C# Parallel Tasks

When you use double-hop authentication (WebBrowser->IIS->SQL Server) code executed on the webserver inside Parallel.Invoke() or Task.Factory.StartNew() is no longer executed as authenticated user (domain\username) but is being changed to (domain\iisservername$). You can see it in Environment.UserName when debuging. So if you're executing any SQL queries as Tasks you might get permission denied errors. The way to fix it is to pass custom TaskScheduler from CurrentSynchronizationContext Parallel.Invoke( new ParallelOptions() { TaskScheduler = TaskScheduler.FromCurrentSynchronizationContext() }, () => { /*do something here;*/ }, ); Task.Factory.StartNew( () => { /*do something here;*/ }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext() ); This is a good article about SynchronizationContext It's All About the SynchronizationContext

SQL Copy data in batches

-- SOURCE TABLE DECLARE @ Table 1 TABLE ( AsOf DATETIME , Company VARCHAR (50), Name VARCHAR (50) ) INSERT INTO @ Table 1 SELECT ' 20130101 ',' Company1 ',' John ' UNION SELECT ' 20130102 ',' Company2 ',' Tom ' UNION SELECT ' 20130101 ',' Company3 ',' Peter ' UNION SELECT ' 20130102 ',' Company4 ',' Ian ' -- DESTINATION TABLE DECLARE @ Table 2 TABLE ( AsOf DATETIME , Company VARCHAR (50), Name VARCHAR (50) ) -- BATCH TABLE DECLARE @Batches TABLE ( AsOf DATETIME ) INSERT INTO @Batches SELECT DISTINCT AsOf FROM @ Table 1 -- COPY IN BATCHES DECLARE @AsOf DATETIME WHILE ( Exists ( SELECT 1 FROM @Batches)) BEGIN TRY BEGIN TRAN SELECT @AsOf = MIN (AsOf) FROM @Batches PRINT CONVERT ( VARCHAR (20),GETDATE(),20) + ' , ' + ' Copying data for: '+ convert ( VARCHAR (8),@AsOf,112) INSERT INTO @ Table 2 ( ...

C# Convert double to decimal

This is a workaround to Convert.ToDecimal(Double) limitation of 15 significant digits by using ‘R’ Round-trip Format Specifier . Convert.ToDecimal Method (Double) “The Decimal value returned by this method contains a maximum of 15 significant digits. If the value parameter contains more than 15 significant digits, it is rounded using rounding to nearest. The following example illustrates how the Convert.ToDecimal(Double) method uses rounding to nearest to return a Decimal value with 15 significant digits.” decimal .Parse(dbl.ToString(" R ")) [Test] public void ConvertDoubleToDecimal() { Compare(1.00000000000006d, 1.00000000000006M); Compare(1.00000000000004d, 1.00000000000004M); Compare(1.000000000000066d, 1.000000000000066M); Compare(1.000000000000044d, 1.000000000000044M); } private void Compare( double dbl, decimal dec) { Convert.ToDecimal(" 0.d0d. "); var d1 = Convert.ToDecimal(dbl); var d2 = new Decimal(dbl); var d3 = de...

IComparable<> inheritance in SortedDictionary

[Test] public void Test() { var dic = new SortedDictionary<BaseClass, string >(); dic.Add( new BaseClass(){Number = 1}, " "); dic.Add( new ExtendClass(){Text = " One "}, " "); Assert.True(dic.ContainsKey( new BaseClass() { Number = 1 })); Assert.False(dic.ContainsKey( new BaseClass() { Number = 2 })); Assert.True(dic.ContainsKey( new ExtendClass() { Text = " One " })); Assert.False(dic.ContainsKey( new ExtendClass() { Text = " Two " })); } public class BaseClass : IComparable<BaseClass> { public int Number { get ; set ; } public virtual int CompareTo(BaseClass other) { return Number.CompareTo(other.Number); } } public class ExtendClass : BaseClass, IComparable<ExtendClass> { public string Text { get ; set ; } public override int CompareTo(BaseClass other) { var other2 = other as ExtendClass; return other2 == null ? base .CompareTo(othe...

Exception handling in multithreaded C#

try { Parallel.Invoke( () => { Console.WriteLine(" Starting Job 1.. "); Thread.Sleep(3*1000); Console.WriteLine(" Starting Job 1.. SUCCESS "); }, () => { Console.WriteLine(" Starting Job 2.. "); throw new Exception(" Job 2 Failed "); } ); } catch (AggregateException ex) { Console.WriteLine(ex); foreach (var innerEx in ex.InnerExceptions) { Console.WriteLine(innerEx); } }

How to find PID of Windows Service

sc queryex < servicename >

C# Convert List IEnumerable<T> to 2D multi-dimensional array

//extension method public static object [,] To2DArray<T>( this IEnumerable<T> lines, params Func<T, object >[] lambdas) { var array = new object [lines.Count(), lambdas.Count()]; var lineCounter = 0; lines.ForEach(line => { for (var i = 0; i < lambdas.Length; i++) { array[lineCounter, i] = lambdas[i](line); } lineCounter++; }); return array; } [Test] public void Test() { var lines = new List<Line>(); lines.Add( new Line() { Id=1, Name=" One ", Age=25 }); lines.Add( new Line() { Id = 2, Name = " Two ", Age = 35 }); lines.Add( new Line() { Id = 3, Name = " Three ", Age = 45 }); //Convert to 2d array //[1,One,25] //[2,Two,35] //[3,Three,45] var range = lines.To2DArray(x => x.Id, x => x.Name, x=> x.Age); //test the result for (var i=0;i<lines.Count;i++) { for (var j=0;j<3;j++) //3 lambdas passed to function { Console.Wr...

MVC4 auto refresh partial view

Image
* Create new MVC4 application and make sure you configure unobtrusive-ajax as described in How to use MVC3 with AJAX * Create Controller /Controllers/HomeController.cs public class HomeController : Controller { public ActionResult Index() { var model = new ViewModel(); model.Now = DateTime.Now.ToString(); return View(model); } public ActionResult Refresh() { var model = new ViewModel(); model.Now = DateTime.Now.ToString(); return PartialView(" IndexPartial ", model); } } public class ViewModel { public string Now { get ; set ; } } * Create view /Views/Home/Index.cshtml @using MVCTest.Controllers @{ ViewBag.Title = "Index"; } < h2 > Index </ h2 > < a id = "button" title = "Refresh now" > Refresh Now </ a > < a id = "toggleButton" title = "Auto refresh every 5 seconds" > Auto Refresh </ a > < div id = "PartialDiv...