2014-09-22

Entity Framework on system databases

Entity Framework supports code only entity models. The default behavior is to deploy this model to the connected database. If you want to access system databases this is unacceptable. Fortunately this can be disabled. Unfortunately it's not easy. You have to implement an custom database initialization strategy. The following example is adding an check if the code model is compatible with the current database.

private class DatabaseInitializer : IDatabaseInitializer<SqlServerCatalog>
{

    public void InitializeDatabase(SqlServerCatalog context)
    {
        if (!context.Database.CompatibleWithModel(false))
            throw new Exception("");
    }
}

Now you habe to override the static constructor of your implementation of the DbContext class:

static YourDBContext()
{
    System.Data.Entity.Database.SetInitializer<YourDBContext>(new DatabaseInitializer());
}

2014-09-21

Docker easy with fig

Playing with Docker is easy. More easy using fig. [http://www.fig.sh/] It's very easy to create an configuration file stating all required dockerized services. The services can be easily linked by name. E.g. if you need a Zookeeper instance for one or multiple Kafka instances. [https://github.com/wurstmeister/kafka-docker/blob/master/fig.yml] The company behind is orchard laboratories. It provides cloud based docker hosts. The company was acquired by the Docker Inc. in July 2014.

2014-09-20

Active Directory user rename and SQL Server

Renaming users is easy. Spreading the news about it is hard. Especially the SQL Server is ignorant about changes. All security tokens for an user or group is cached for Performance reasons. The only way to force an update is to drop the existing cache using: DBCC FREESYSTEMCACHE ('TokenAndPermUserStore')

Format data types on SQL Server 2012+

I was required to format multiple variables and concat them into a beautiful string. I stumbled upon the FORMAT function. A build-in function since SQL Server 2012.Look at http://msdn.microsoft.com/en-us/library/hh213505(v=sql.110).aspx

Missed the part that states:
The following table lists the acceptable data types for the value argument together with their .NET Framework mapping equivalent types.

They are serious about this. Tried the bit data type and it failed miserably.
So you still have to do a
 convert([n]varchar(1), @bit_value)  
for the value as number or
 case when @bit_value = 1 then 'TRUE' when @bit_value = 0 then 'FALSE' else 'NULL' end  
for the value as text.