Skip to main content

Posts

Showing posts from October, 2013

Kendo UI Window Widget: Window only opens once

On a project I’m using the Telerik Kendo UI widgets and I’m enjoying the experience so far. They are a lot better than the default jQuery UI controls(and better documented). However with the Window widget I had a small issue I wanted to share(together with a solution). The first time I used the Window widget I used the following JavaScript: This code will open a Window when the user clicks on a specific link on my webpage. This code works as expected BUT only the first time that I load my page. If I close the window and click on the link again nothing happens… After some trial and error I found a solution, it seems like you have to create the Window widget only once and then re-use it each time you want to open a new Window. Here is my updated code: You can see that we only create a Window object once and then re-access it through the data property of the div.

Free ebook: 45 database performance tips for developers

Redgate provides us with a free copy of 45 Database Performance Tips for Developers . It contains SQL Server performance tips and tricks recommended by some of the smartest minds in the Simple Talk community, including SQL Server MVPs. Download your copy here . Remark: Registration is required.

TFS Build Server Error: The build service host XXX is currently owned by XXX. A service host may only be active on one machine at a time.

A customer reported me the following problem with their TFS Build Server: We had several occurrences of an error on the build development server that prevents the build controller from starting. In the TFS Event log on the server, this error message appears: Exception Message: The build service host XXX is currently owned by XXX. A service host may only be active on one machine at a time. (type BuildServiceHostOwnershipException) A service restart will not correct this error. One workaround we found is to reinitialize the build server status in the Team Foundation Server collection database. Execute the following steps to do this: Determine what is the ServiceHostId of your build server (to get a key for the update): Update the record to reinitialize status: Remark: Be careful! This is a workaround, NOT an officially supported solution.

WatiN error: Could not load file or assembly 'Interop.SHDocVw’

For a customer I’m comparing multiple UI testing frameworks. One of these frameworks I’m looking at is WatiN . I started simple, I created a new test project in Visual Studio, installed the required assemblies through NuGet and copied the sample code from the website. But when I tried to run this test, it failed with the following error message: Test Name:        TestMethod1 Test FullName: WatinTestProject.UnitTest1.TestMethod1 Test Source:      c:\Projects\Test\WatinTestProject\WatinTestProject\UnitTest1.cs : line 12 Test Outcome: Failed Test Duration:   0:00:00,0910315 Result Message:              Test method WatinTestProject.UnitTest1.TestMethod1 threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Interop.SHDocVw, Version=1.1.0.0, Culture=neutral, PublicKeyToken=db7cfd3acb5ad44e' or one of its dependencies. The system cannot find the file specified.WRN: Assembly binding logging is turned OFF. The error i

Secure your cookies!

As we are building more and more web applications in the Cloud, security becomes a key aspect of every application. Before we felt a little bit more safe behind the company firewall but these days are gone… And as your security is as strong as your weakest link, it is important to understand every aspect of it. One possible risk is the (wrong) usage of cookies. Most of the time when you create a cookie inside your ASP.NET application, you  don’t want to read it on the client. With a tool like https://www.cookiecadger.com/ , it becomes very easy to steal someone's authentication cookie. How can we prevent this? In ASP.NET, you have to set the HttpOnly flag to true when creating a cookie: Unfortunately the default for HttpOnly=false, so if you forget to set it somewhere you’re in trouble. Probably better is to set HTTP only as the default for all cookies to via the web.config: <httpCookies httpOnlyCookies="true" /> More info: http://www.troyhunt.com/2013/03/c-is

Saxon: Write XQuery in .NET

They are not many solutions out there in .NET that allow you to combine the power of XQuery with a C# API. The built-in XSLT support in .NET is very limited and only supports the XSLT 1.0 specifications. One of the best options you have is Saxon , a powerful XSLT and XQuery processor. The only disadvantage of this tool is that the syntax is very JAVA oriented, which makes it sometimes counterintuitive for .NET developers. A sample:

Simplify XPath development by using XQuery

Most people have heard about XPath , it gives you a powerful syntax to navigate through elements and attributes in an XML document.  Most of the time XPath is used to transform one XML document to another(through XSLT). I always found the XPath syntax hard to read, especially if your expression start to get more complex. That’s one of the reasons why I always tried to avoid using XPath and preferred writing a small C# program and use Linq to XML . What I didn’t know is that XML had it’s own query language, XQuery , which offers you a similar more readable experience when walking through XML files. XQuery itself uses XPath underneath but it hides the complex expressions behind a nice and clean functional-style syntax. From w3schools : And here is a sample of the syntax:

Sharpen your TDD skills: Coding Katas

Looking for some good exercises to train your Test Driven Development skills(or train your programming language skills)? On https://github.com/garora/TDD-Katas you find a list with some of the most well known Coding Katas, like the Bowling Game kata, the FizzBuzz kata, and so on… For each of these Katas a solution is available in C# together with all the test. Certainly worth checking out!

Caliburn.Micro: Async/Await

Caliburn.Micro always had the concept of Coroutines which allowed you to write asynchronous code in a synchronous way. Starting from .NET 4.5 with the introduction of the async and await keywords, Microsoft introduced the concept of Coroutines in the language itself. So if you want to use the same code in Caliburn.Micro with the async syntax, it becomes: More information here: http://caraulean.com/blog/2013/07/15/using-caliburn-micro-with-async-await/

Dependency Injection with Microsoft Unity Guide

Thanks to frameworks like Unity, StructureMap,… concepts like Inversion of Control and Dependency Injection have become mainstream in the .NET world. They allow the removal of hard-coded dependencies and make it possible to assemble a service by changing dependencies easily, whether at run-time or compile-time. They promote code reuse and loosely-coupled design which leads to more easily maintainable and flexible code. The Microsoft Patterns and Practices team released a new guide about Microsoft Unity . It covers various styles of dependency injection and also additional capabilities of Unity container, such as object lifetime management, interception, and registration by convention. It also discusses the advanced topics of enhancing Unity with your custom extensions. The guide contains plenty of trade-off discussions and tips and tricks for managing your application cross-cutting concerns and making the most out of both dependency injection and Unity. These are accompanied by a r

Android Emulator performance tips

The most annoying part of the whole Android development experience is the Android emulator. Even on up-to-date hardware it remains a slow beast. Here are some general tips and recommendations to improve the experience: Tip 1: Avoid the emulator at all. Test on a real device when possible. Tip 2: Keep the emulator resolution as low as possible. Tip 3: Install the Intel HAXM and use an x86 emulator image instead of an ARM one. Tip 4: Use VirtualBox as an Android emulator. Tip 5: Create a snapshot and load the emulator from this snapshot afterwards. Tip 6: Use the BlueStacks player.

SQL Server: Get a list of most expensive queries

I’m not a DBA but still I want to know what’s happening inside our SQL Server. You never know what you can achieve with a little bit of optimization. On Brent Ozar’s blog I found the following query that returns the top 20 most resource-expensive  queries: If you execute this query, you not only get the Average CPU, Duration, … but also the query plan. By clicking on the query plan XML, you can even get a graphical representation: Nice!

An incompatible DacFx version is installed

When trying to connect to a SQL Server Database using Visual Studio 2012, I was welcomed by the following error message: I recently installed the SQL Server Data Tools – BI package which is not the same as the SQL Server Data Tools itself(always fun to use confusing names). This seemed to have messed up my Visual Studio Installation. Luckily you can fix it by installing the latest version of the SQL Server Data Tools – October 2013 Update .

Team Foundation Server: Error when creating a new Team Project

A customer forwarded me the following error message they got when trying to create a new Team Project in TFS 2012: Error TF30169: The New Team Project Wizard was unable to download the process template MSF for Agile Software Development v5.0. Explanation The New Team Project Wizard encountered an unexpected error while attempting to download the process template. The download returned the following error: The process cannot access the file 'C:\Users\username\AppData\Local\Temp\TPW_tmp931A.tmp\Build\Templates\' because it is being used by another process. User Action Contact your Team Foundation Server administrator. I was able to solve it by clearing the Visual Studio Team Explorer cache. Execute the following steps: Close Visual Studio if it’s open Delete the Team Foundation cache on the client (be careful, delete the content of the folder only, not the cache folder itself) C:\Users\<yourusername>\Local Settings\

Using sequential guids as identifiers in Entity Framework

The default strategy for ID fields in Entity Framework is the usage of IDENTITY columns. This means that an identity value is generated for you by the database. Disadvantage of this approach is that an extra roundtrip to the database is required to get an ID assigned to an Entity. An alternative approach is the use of GUID’s. They make it easy to generate an unique identity value on the client without the need to connect to the database. However the usage of GUID’s doesn’t come without it’s own set of disadvantages . First of all extra space is required to store the information and second of all it leads to fragmented indexes(due to the randomness of the generated values). To combine the best of both worlds, you can use Sequential Guids. Using sequential guids in NHibernate is easy thanks to the build in guid.comb strategy(read more about it here ). But how can we do this in Entity Framework? I found 2 possible solutions to do this: Use NewSequentialId() One option you have

Fun fact: TFS is using Lernout and Hauspie Speech Technology

While looking through some TFS information I noticed the following fun fact. It seems that Team Foundation Server is using the Lernout & Hauspie speech technology : Remark: This is a blog post that probably only the Belgian readers will understand. It’s a long story about what happened with Lernout & Hauspie(read the wikipedia article if you want to know more).

Help! The Microsoft BIDS are gone?!

After doing a clean install of my pc I also wanted to install the BIDS(=Business Intelligence Designer Studio) to start some Microsoft Report Services development. But I couldn’t find a version for Visual Studio 2012? So where did it go and how should I develop SSIS, SSRS and SSAS stuff using VS 2012? I discovered that with the 2012 release of SQL Server, the BIDS plugin for Visual Studio was renamed to SSDT, SQL Server Data Tools. SSDT is available for both Visual Studio 2010 and 2012. You no longer need the SQL Server installation media to install it but instead you can just download it from the Microsoft Download Center : You can use this version of the Data Tools to develop applications for both SQL 2008, SQL 2008 R2 and SQL 2012(and of course SQL Azure). After installing it, some new templates are added to your Visual Studio:

The !! operator in JavaScript

While walking through a Single Page Application codebase I noticed the usage of the !! operator. No clue what it means but StackOverflow brought the rescue. “The !! operator will convert a value to a boolean first and than invert the result.” JavaScript keeps surprising me…

Entity Framework: Specify a schema name

By default when you are using Entity Framework code first, the default ‘dbo’ schema is used. But what if you want to use a different schema? There are multiple ways to do this. Option 1: Use the ModelBuilder API One way to change the schema is by using the modelbuilder API. To use this override the OnModelCreating option on your db and specify a schemaName using the Fluent API: Option 2: Use attributes Another option is the usage of Attributes on your model classes:

Xamarin AndroidRuntimeException “Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag”

In my Android application I’m using the Azure Mobile Services component to connect to Windows Azure. I want to use the authentication component and let the users login by using their Microsoft account. Here is the code I used: However when I try to run this code, it fails the moment the LoginAsync method is called. This is the exception I get: AndroidRuntimeException “Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag” I found out that I made a stupid mistake. I was passing the BaseContext instead of the Activity itself. When I updated the code to the following it worked as expected: