Data access for MongoDB

The project I’m working on at the moment has a lot of analytics data. This means there’s a lot of inserts and updates in the database and queries have to be fast! At the moment all of this is hosted in a single MS SQL Server which does a pretty decent job. Still, this seems like a perfect scenario to introduce a noSQL database, especially as we are migrating to the cloud to improve performance of the application as a whole.

After a having reviewed a couple of noSQL databases, our weapon of choice became MongoDB. It’s popular, fast and there are a couple of providers which offer it as a hosted solution.

While reviewing MongoDB I discovered you not only need to change your ‘scheme’, but also the way you query the database. I have spent quite some hours on finding out why the performance was so incredibly slow, therefore it seems like a good idea to share my findings.

To make life easier, the most important stuff to set up a connection to a MongoDB store is thread safe. This is great as you don’t have to setup a connection to MongoDB every time you want to use it. In my testing code I’ve set up some static properties to keep the connection alive.

Read more →

Solved spontaneous reboots of WP8 Lumia 925

About 1.5 years ago I received my Nokia Lumia 925 phone as a replacement for my Nokia Lumia 620, which I had lost. I couldn’t be more happy at that moment. It has a great screen, it’s quite fast and nice to look at.

The only downside was, it sometimes rebooted while I was doing something. This happened almost all the time when I was taking a picture, but also when listening to podcasts, driving my car, reading e-mail, etc. It’s rather annoying when you are using a phone and it reboots almost all the time, especially if you don’t know why!

After having read a lot of forums, discussed with some colleagues and tried a lot of stuff myself, I discovered the Wi-Fi Sense (Dutch: Wi-Fi-inzicht). Disabling these options solved the issue of the spontaneous reboots. As I didn’t use these options anyway, I’m not missing out on anything either.

wp_ss_20141002_0001

So, if you are experiencing (a lot of) random reboots on your Windows Phone 8 phone, try turning of the Wi-Fi Sense options. It might help.

Read more →

SQL Azure Data Sync

For quite a couple of years now, the SQL Data Sync software has been available to synchronize data between MS SQL Server databases. This SQL Data Sync however has been decommissioned and we have to resort to the the (new) SQL Data Sync (Preview) nowadays.

SQL Data Sync is a solution/feature which allows you to synchronize data between several SQL (Azure) databases. The best thing is, you don’t have to synchronize your complete database. You can choose which tables and columns need to be synchronized. This is a very nice feature if you have, for example, your database scaled out in multiple regions of the world and some of the data has to be kept in sync.

The new SQL Data Sync has been made available through the Azure management portal. When navigating to the SQL Databases tab you will have an option available to Add Sync, which will create a new SQL Data Sync group_._

For the purpose of this post I have created 2 databases, one located in West Europe and one located in East US.

image

To keep them synchronized I’ve added a new Sync Group via the portal.

When creating the sync group, you have to specify which database will operate as the Hub. Basically this means which database will be the master. It’s also possible to select the conflict resolution in this step. The default value is Hub Wins, but you can also specify the client should win in case of a conflict.

Read more →

Alter all tables in SQL

As I wanted to move an on-premise MS SQL database to Azure SQL I was notified with an error message telling me this:

Error SQL71564: Element Column: [dbo].[SomeTable].[Id] has an unsupported property IsRowGuidColumn set and is not supported when used as part of a data package.

Every table in the database has a GUID (uniqueidentifier) as a primary key and apparently, the ROWGUID is set to YES. It’s too bad there isn’t much documentation on the ROWGUID option telling us what it actually does. By searching for this feature I have discovered it is meant to create a unique key across multiple servers, only useful if you want to enable the SQL Server Replication feature. I’m not really sure about this description, as a uniqueidentifier (GUID) should be unique no matter what. However, this post is not about GUIDs in SQL.

Because of the above error, I had to change all tables in the database. The ROWGUID had to be removed. This can be done manually of course, but that’s not really fun.

I decided to generate a query which creates an ALTER script for me. The script will iterate through all tables and SELECT the query which needs to be run. All which is left to do is copy the result to a query window and run it.

Read more →

Firewall blocks almost everything, can’t do development work

Sometimes you’re hired by a company which is a bit rigorous on blocking outgoing communication. A security consultant would probably agree on this practice, but most developers won’t. Nowadays a lot of services in the cloud operate on different ports. Azure services don’t always operate on port 80 and 443, hosted noSQL providers have connection strings with (seemingly) random ports, etc. It’s not always easy to get approval to open ports in the company firewall, especially if you’re doing some tests and proof of concept projects. A way to get around this policy is to create a virtual machine in Azure.

When you choose to create a new virtual machine from the gallery you can create an image with Visual Studio pre-installed on it. Even the latest versions are available!

image

After completing the wizard you’ll have to wait a few minutes for the machine to spin up.

Don’t be happy just yet. When you try to connect to the machine, you’ll probably get a timeout or some other connection problem. This is because the configured RDP port is probably also blocked by your company firewall. A way to fix this is to set the public RDP port to 80 or 443 (which company would block normal HTTP(S) traffic?). This setting can be configured on the Endpoints tab of the virtual machine.

Read more →

Migration from Orchard to MiniBlog

The past couple of days I’ve been working on migrating my blog from the Orchard CMS to MiniBlog. The main reason for me to migrate to a different system is because I don’t work a lot with Orchard anymore. There were also some crashes from time to time which I couldn’t explain.

I’m currently hosting my websites on Azure Websites, because of that I didn’t feel much for using a database system. SQL Azure is very nice of course, but it can also be quite expensive, especially if you don’t really need the features. The alternative is SQL Compact, but I’m not very keen on using this as well.

While searching for a database-less blogging system, I came across several solutions like Ghost, Jekyll and MiniBlog. All of these systems are slightly different and work with different techniques. The main reason I’m using MiniBlog as my new blogging engine is because it’s based on .NET. I could list all the cool features which are included, but as it’s already stated on the GitHub page, I won’t repeat it over here.

MiniBlog is a system which saves it’s posts in XML files. Therefore, I had to migrate all of my posts from the Orchard database to the files which MiniBlog understands. There’s already a project on GitHub called MiniBlogFormatter. This tool is able to export posts from DasBlog, BlogEngine.NET and WordPress to the MiniBlog format. I’ve used the code from this project as a basis for exporting my own Orchard posts.

Read more →

2 SharePoint quirks which kept me busy

There are 2 ‘features’ in SharePoint (MOSS2007) which have kept me busy for quite some time in my last project. Yes, you’ve read it right the first time, my latest project was a MOSS 2007 web portal. Of course these issues aren’t really quirks as the product behaves by design, but it has kept me busy for more time as I would bargain for.

First quirk

For some reason I had to create a console application to query the SharePoint user list and delete the users. Normally this doesn’t pose a problem at all. However, this time the following error was thrown every time:

The Web application at https://your-website-here:80 could not be found.
Verify that you have typed the URL correctly.
If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

Quite strange, as the website does exist, I even double checked it.

After doing some research on the matter it turns out you need to specify the Platform target for your application. Mine was set to Any CPU and had to be changed to x86. After changing this specific option the code was running correct.

Read more →

Running commands as Administrator in Windows

There are some cool features available in Linux. In an earlier post I already mentioned the apt-get functionality which is now also offered in Windows via Chocolatey. One of the other cool features is being able to execute something in the terminal as an Administrator by specifying sudo in the command.

Lucky for us Windows people, someone has created a tool which is able to do something similar as the Linux sudo-command. The tool is called Elevate and can be downloaded from over here: https://code.kliu.org/misc/elevate/

After you have downloaded the zip-file from the website, copy the appropriate executable to your System32-folder and you are good to go!

By specifying the Elevate command in the command prompt, PowerShell window, Windows Search or Run-window the command will now be executed as an Administrator.

clip_image002

image

clip_image002[6]

Depending on your UAC settings, you are still prompted with the question if you really want to run the application (Notepad) as an Administrator.

I think this functionality could be extremely useful if you want to run specific commands of a script as an Administrator.

Read more →

Chocolatey introduction

Even though the Windows operating system is one of the best in my opinion, there are always something which is only available in a different OS. For example the apt-get functionality in Linux. I don’t know how this works exactly, but from my basic understanding it’s some kind of repository with a lot of software and libraries which you can download to your device by typing something like the following in a terminal window:

apt-get SomeSoftware

Why this feature isn’t available by default in Windows is a mystery to me.

Quite some time ago, Scott Hanselman blogged about Chocolatey. Chocolatey is something similar to the apt-get feature from Linux, but now available on a Windows machine. (disclaimer: it’s not really the same, but works for me)

Ever since reading this post I wanted to use this awesome piece of software, but all my systems were already up-to-date and never needed it. As of this week, I’ve started working on a new project. Therefore, a new virtual machine had to be installed and configured. An awesome excuse to start using Chocolatey!

With Chocolatey you can install all kinds of software, just by typing a command in your Command Prompt or PowerShell window. It will automatically download and install the software for you. The only thing you need to do is wait for the command to finish.

Read more →

Creating a Web API to work with XML requests

For a project on the side I’m creating a Web API which has to parse XML requests in a POST. The first method I’ve written looks like this:

[HttpPost]
public HttpResponseMessage IndexPost(RequestModel requestMessage)
{
	return new HttpResponseMessage(HttpStatusCode.Accepted) { Content = new StringContent("This is the POST API response from BusinessPartner!") };
}

To test the new API I’m using the Postman Chrome plugin. With this plugin you are able to send requests to an endpoint and see what the response is. Of course you can also use Fiddler for this, but I like the user experience of Postman a bit more.

There were a few problems I encountered during the development of the Web API.

The first problem was this error:

{
    "message": "An error has occurred.",
    "exceptionMessage": "No MediaTypeFormatter is available to read an object of type 'RequestModel' from content with media type 'text/plain'.",
    "exceptionType": "System.InvalidOperationException",
    "stackTrace": "   at System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n   at System.Net.Http.HttpContentExtensions.ReadAsAsync(HttpContent content, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n   at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable`1 formatters, IFormatterLogger formatterLogger)\r\n   at System.Web.Http.ModelBinding.FormatterParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.Tracing.Tracers.FormatterParameterBindingTracer.<>c__DisplayClass3.<executebindingasync>b__1()\r\n   at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEndAsync(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Func`1 execute, Action`1 endTrace, Action`1 errorTrace)\r\n   at System.Web.Http.Tracing.Tracers.FormatterParameterBindingTracer.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.Controllers.HttpActionBinding.<>c__DisplayClass1.<executebindingasync>b__0(HttpParameterBinding parameterBinder)\r\n   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()\r\n   at System.Threading.Tasks.TaskHelpers.IterateImpl(IEnumerator`1 enumerator, CancellationToken cancellationToken)"
}

This was quite surprising as I thought I was sending a proper request which could be serialized. For reference, I was sending a POST request to https://localhost:11210/api/businesspartnerapi/ in this format:

Read more →