Skip to content
Jun 19 14

Test connection to SQL server from Windows Server without SQL Server Management Studio

by mstrid

The other day I found a nifty tool for testing the connection to a SQL Server database from Windows Server without having to install the full SQL Server Management Studio.

I can’t find any proper for the tool but you do like this:

  1. Create an empty file and give it any filename but make sure the file extension is “.udl”.
  2. Double-click the file.
  3. A dialog opens where you can enter hostname/ip address, username, etc and test the Connection.

More information in this blog post.

Jun 17 14

Prevent CSS class or rule-set from rendering when using LESS mixins

by mstrid

Sometimes, when working with LESS, I write CSS rule-sets that are only used as LESS mixins and in this case it is of course unnecessary to render the rule-set on its own in the CSS. The other day I stumbled upon the fact that if you make the CSS rule-set a LESS parametric mixin with no arguments the mixin is not outputed. So instead of writing

.a {
color: red;
}

.b {
.a;
}

Write

.a() { 
color: red;
} 

.b { 
.a; 
}
May 15 14

System.InvalidOperationException: Timeout expired exception in EPiServer 7.5

by mstrid

Today I encountered an exception when developing a new site based on EPiServer 7.5 CMS:

Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.

The cause was very simple but maybe not that inutitive, I had used the wrong connection string. Maybe this short blog post could help someone else.

May 14 14

New localization format for content types in EPiServer 7.5 CMS

by mstrid

Version 7.5 of the EPiServer 7.5 CMS (and I guess it goes for Commerce etc too) uses a new format for the language XML files for translation/localization of the content types. I took me a couple of hours of scratching my head and searching for typos before I stumbled upon this blog post on EPiServer World.

I guess it is part of some breaking changes documentation somewhere but it was Linus blog post that helped me.

It seems to be only the localization of the content types that has changed, the old format from EPiServer 7 and older is still valid when translating for example enumeration.

Jan 9 13

New project – Mjölk&bröd

by mstrid

I just updated the Projects page with a few lines about my latest personal Project, the smart shopping list application Mjölk&bröd.

Aug 27 12

Self-referencing many-to-many relationships in Entity Framework 5 Code-First

by mstrid

When trying to use the following POCO class to create the database schema using Entity Framework 5 Code-First the default data annotation mapping couldn’t handle the self-referencing many-to-many relationship that is specified by the RelatedProducts property.

image

The simple solution is to use the fluent API and add the following method to the DbContext class:

image

Now a join table is created automatically that handles the many-to-many relationship.

For more information see this article and this article.

Aug 24 12

Fix for freezing problems in Windows 8 (using bootcamp on a iMac 27″)

by mstrid

I was really impressed by Windows 8 after having installed it on my iMac 27″ and the only thing that eluded me (and still does) is getting the speakers to work. There is still no official bootcamp drivers for Windows 8 so I have only used the drivers included in Windows 8.

But my happiness soon turned into horror when the computer began to freeze, and I mean REALLY freeze, I had to kill the power to restart it. I first suspected driver issues but luckily it there turned out to be a much easier workaround.

EDIT: The link to the original article on WithinWindows appears to be dead (per 2012-10-26) but the following SO thread contains the necessary command.

Aug 11 12

“Access is Denied” in a ASP.NET web page that uses SQL Server Compact

by mstrid

Yesterday I tried to deploy an ASP.NET MVC 4 web site to the Binero web hosting servers but when trying to access the site I got the following error:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

The simple but maybe not obvious solution was to change the read/write/execute permissions of the SQL Server Compact (sqlce) binaries folders (“amd64” and “x86”) in the bin folder so that they have the same permissions as the bin folder itself. I just let the permissions set on the bin folder be inherited by the subfolders.

More, related information is available here.

Jun 13 12

Problem connecting Xbox 360 to Windows Media Center on Windows 7

by mstrid

Yesterday I had the same problem connecting my Xbox 360 to my Windows Media Center running on my Windows 7 (x64) HTPC as I know I encountered about a year ago, but I couldn’t for my life remember how I solved it then. So I had to start googling again and after a couple of hours I found the solution in an obscure comment to a forum thread, it wasn’t even marked as the solution (!). This time I will post the solution here so it is easier to find the next time. Smile

First a rather extensive problem description then the solution at the end.

Problem scenario

When adding the Xbox as an extender to the Windows Media Center, after entering the “PIN code” you get

Configuration Error
An error was encountered while configuring your computer for use with this extender.

on the the Windows Media Center computer while the Xbox still shows

Connecting to Windows Media Center

or something similar.

If you don’t run Windows Media Center in full screen mode you will notice that the computer tries to install some drivers for the extender which fails.

If you open the event viewer you will find the following error:

Untitled

with the following details:

Log Name:      Media Center
Source:        Microsoft-Windows-Media Center Extender
Date:          2012-06-10 18:47:19
Event ID:      543
Task Category: Configuration
Level:         Error
Keywords:
User:          VARDAGSRUMMET\Mikael
Computer:      Vardagsrummet
Description:
Media Center Extender Setup failed to create the PnP device with ID: uuid:10000000-0000-0000-0200-00125AB67BAB (timed out after 120000ms).

Error: Element not found.
Event Xml:
<Event xmlns=”http://schemas.microsoft.com/win/2004/08/events/event”>
<System>
<Provider Name=”Microsoft-Windows-Media Center Extender” Guid=”{7B7838A3-6562-4269-BB7A-97B0D9593882}” />
<EventID>543</EventID>
<Version>0</Version>
<Level>2</Level>
<Task>4</Task>
<Opcode>0</Opcode>
<Keywords>0×8000000000000000</Keywords>
<TimeCreated SystemTime=”2012-06-10T16:47:19.496200000Z” />
<EventRecordID>1115</EventRecordID>
<Correlation />
<Execution ProcessID=”3624″ ThreadID=”5512″ />
<Channel>Media Center</Channel>
<Computer>Vardagsrummet</Computer>
<Security UserID=”S-1-5-21-3664238277-914888578-113142783-1000″ />
</System>
<EventData>
<Data Name=”ID”>uuid:10000000-0000-0000-0200-00125AB67BAB</Data>
<Data Name=”Timeout”>120000</Data>
<Data Name=”Error”>-2147023728</Data>
</EventData>
</Event>

Now, finally, the solution:

Solution

First some credits:

Big thanks to nightrider_8t5 for posting the comment at 2011-11-01 05:21 in this forum thread. I for sure had gone mad if I hadn’t read your solution!

To summarize, the problem is the startup mode of the “UPnP Device Host” Windows service, for some reason this should be set to “Automatic” for the Windows Media Center extender so install properly.

SNAGHTML949d172

To fix this problem we need to change the startup type from “Manual” to “Automatic” (and I also needed to restart the Windows Media Center computer).

Mar 13 12

Verify an array parameter in Moq

by mstrid

Recently I encountered a scenario where I wanted to write a unit test that verifies that a method on a mock (using Moq) was called with the correct array parameter. The problem was that the array was built dynamically in the method calling the object that was mocked so I couldn’t use a simple reference test like this:

byte[] expectedArray = new byte[] { 1, 2,3 };
mock.Verify(m => m.Method(expectedArray));

My first thought was CollectionAssert but I couldn’t fit this into the Moq Verify method.

So I started to play around with different LINQ expressions to be able to write a function that verifies the elements in the passed array against an expected array. The function I came up with is far from perfect (for example it is having trouble handling if the method was called multiple times with arrays of different lengths) but it does the work for me:

byte[] expectedArray = new byte[] { 1, 2,3 };
mock.Verify(m => m.Method(It.Is<byte[]>(a => a.Where((b, i) => b == expectedArray[i]).Count() == expectedArray.Length));

Basically what it does is to count how many element in the passed array that are equal to the corresponding element in the expected array and then checks that it is the same number as the number of expected elements.

This will find any element that does not match the expected array. It will most probably throw an exception if the passed array contains more elements than the expected array but it should be used within a unit test so I guess this is ok since the important thing is that the UT fail.