Thursday 19 January 2012

Creating a user on SQL server which maps to a computer account

Sometimes we need to grant a computer rather than a user account access to SQL Server / database.

Unfortunately SQL Server Management Studio doesn't allow you to select a computer account when you create a new login.

Fear not as with most SQL related problems we can fix this via a SQL query which we can run from inside management studio.

EXEC master.dbo.sp_grantlogin @loginame = N'DOMAINNAME\COMPUTERNAME$'

Obviously replace DOMAINNAME with the name of your domain and COMPUTERNAME with the computer name.




Monday 16 January 2012

Running C# / .NET apps on server core

I recently migrated one of our file servers to the server core edition of Server 2008 R2, mainly because we needed to reclaim some of the disk space as the VMDK for the data partition was very heavily over allocated and in thick mode. 


So to regain the space we build a new virtual machine running Server 2008 R2 SP1 Server Core. The data was already part of a DFS tree so we just added the new data location on the new virtual machine as a additional target and waited for the data to complete replication before removing the old server as a target for the DFS folder.


I digress, the original server was running a number of C# / .Net applications that perform house keeping operations on the data and are run via scheduled tasks. 


We copied the applications over and setup the scheduled tasks, but unfortunately we were experiencing the following error:


The application failed to initialize properly (0xc0000135)





We had already installed .NET Framework 4.0 for Server Core but were still receiving the error message, initial thoughts were that the application referenced components that may have used GUI components of Windows which were missing in server core. 


A quick inspection of the source code for the application revealed that this probably wasn't the case, and the point proved by running a blank C# application which still wouldn't run.


Inspection of the download page for .NET Framework 4.0 for Server Core :
http://www.microsoft.com/download/en/details.aspx?id=22833 


reveals that there are several windows components which need to be enabled as well so here are the steps:
  • Turn on WoW64: Start /w ocsetup ServerCore-WOW64
  • Turn on .NET 2.0 layer: Start /w ocsetup NetFx2-ServerCore
  • Turn on .NET 2.0 layer for WoW64: Start /w ocsetup NetFx2-ServerCore-WOW64
  • Install .NET Framework 4.0 for Server Core
We had performed step 2 and step 4, but the application was targeting a 32bit Platform target as Visual Studio 2010 defaults to, so the WoW64 components were also required.