Thursday, 8 December 2016

NHibernate.StaleStateException : Unexpected row count

Situation:
Console application with NHibernate and a MySQL database. The application read several (large) files with data and process it to the database. For several reasons, all entries that are read from the files needs to be compared with existing entries in the database. New one's should be added, existing entries should be updated (if needed) and entries that does not exist anymore in the import files needs to be update (property set to inactive = true). So far so good.

Problem:
I ran several times into the NHibernate.StaleStateException with the unexpected row count message.
I changed from session.save() and session.flush() to a transaction with commit way of dealing with the objects. I also started to use Parallel.ForEach when processing the read entries for performance reasons. During testing (with smaller files) everything went well. Till I started to read files from over 15Mb (I got even files of > 60Mb). That was the moment that those NHibernate.StaleStateException's were fired.

Solution:
After searching a lot and reading a lot of flushing, saves, transactions and versions I still got not the correct answer for my problem.
However, I've found the solution. It was not really an Nhibernate issue, but a MySQL issue. I had to change a few database parameters:
  • innodb_buffer_pool_size. I changed the default value of 8M to 512M. This speed up the entire process a lot. On production server(s) this value can be set higher as well (depending on the available RAM of the machine).
  • innodb_log_file_size. I changed this one to 128M
  • max_allowed_packet. If this value is to small, NHibernate will fire those StaleStateExceptions if you are processing such amount of data(files). So I changed it to 100M
Those parameter you can find in the my.ini file of MySQL (location of my file is at C:\ProgramData\MySQL\MySQL Server 5.7\my.ini). More info of those parameters can be found in the my.ini file.
After changing those parameters, you need to restart the MySQL service.

For me, those 3 db-parameters did the trick.

Monday, 18 July 2016

Tilde key not working in VMware fusion

Problem:

Today I ran into a small but frustrating problem. The tilde key (~) didn’t work on my VMware fusion machine.

Situation:

I run Windows 10 in VMware fusion on a Macbook Pro. I searched a bit around the internet but didn’t find the right solution. By the way, my keyboard layout is US, so the ‘~’ key should be on the key just left from the ‘1’.
Some trial and error with keyboard combination with CTRL, ALT, Winkey etc didn’t work out. Strangely enough, I got it to work on the command prompt by pressing SHIFT+ALT+`, but that didn’t work on e.g. Notepad++ and Visual Studio.

Solution:

I found out that you can fix that in the settings of the VM itself. You don’t need to shutdown you VM. Just do the following:

  • Open the Settings of you VM
  • Click on ‘Keyboard & Mouse’
  • Just under the list of Profiles, you will see a gear wheel button which you can expand.
  • Click in the gear wheel popup menu on the option ‘Edit profile’
  • In the popup window, click on the tab ‘Key Mapping’ and unselect the option ‘Enable Language Specific Key Mappings’. This will do the trick (a least for me).
  • Close all settings windows, return to your (running) VM and voila, the ‘~’ will work back again.

I assume that this will work on other Windows versions on VM's as well. Just give it a try.

Happy programming!

Monday, 9 May 2016

MS Access and LINQPad

Situation:

As most developers, using LINQ queries saves a lot of time and works absolutely great. For me one of the greatest tools for quick and easy querying data and testing code is LINQPad. However, sometimes you get a project where the (backend)database is MS Access (yes, it still happens, even in 2016 :) ).

Problem:

And there starts the problem. There is no MS Access driver for LINQPad, at least no free one.

Solution:

But we are lucky, LINQPad provides a way to create custom drivers. So one of my colleagues, Frank den Outer, made a driver for MS Access to enable you to connect to *.mdb and *.accdb and allows you to query on data from LINQPad on MS Access database (even with password protected ones). So the credits of this post goes to him!

See the screenshots below:






Our company, DNM, offers you this driver for free. You can download is here: MSAccessDataContextDriver.lpx. After the download, start LINQPad, and when creating a new connection, you can easily add the downloaded driver.

Happy programming!

Android Screen Recording on Mac

Scenario:

For one of the apps we are developing, I needed to make a screen cast of some strange behaviour inside the app on Android. But how can you record screen activity from a Android device on Mac OS X?

Solution:

After a little bit of searching, the solution was actually pretty simple. You need to do the following:

1. Install the Android Tool
Download the Android Tool from GitHub (please check out the GitHub project page to keep track of updates and news). The download gave you a zip file. Unzip the file and place the tool inside the application folder on your Mac.

2. Prepare your Android device
In order to be able to establish a successful communication between your Android device and the Mac, you have to enable the 'Developer Options'. Inside the Developer Options, you need to enable the 'USB Debugging' feature. If you like, you can also enable the feature that shows your touch actions on the screen.

3. Launch the Android Tool
Start the Android Tool (note: you may get the warning that the app is from an unidentified developer). Once the app is opened, simply plug in your Android device

4. Start Recording
The tool is as easy as it can be:
Click on the camera button to take a screenshot or click on the camcorder button for a screen recording. When done with screen recording, press the red square (stop) button which appeared on the camcorder button place. You can record as long as you wish :).
The files created will be stored in an 'AndroidTool' folder on your desktop.

Note: You won't be able to record audio with this tool and neither you can take screenshots of record videos of protected videos.

Last tip: once you have your screencast video file, put it through Handbrake. This will decreases you file size a lot (e.g. 8.3 MB to 2.4 MB)

Monday, 1 June 2015

Fix slow boot-up on Mac

Problem
Recently I ran into a frustrating issue on my new MacBook Pro Retina (with 512MB SSD). The time of (re)boot took a lot of time, holding the screen black for a long time.
I checked several tips, but it was not due to old hardware (...), also not that my disk was full (more than 50% free space).
I searched a lot and found a solution that works actually pretty well and seems really stupid to me (a kind of Microsoft-type-solution-when-something-unexpectedly-stop-working-well).

Solution
What you need to do is to go to System Preferences, and selecting Startup Disk. Then, select your primary disk, and hit ‘Restart’ from the same window.


That's all! It worked for me pretty well!
By the way, it seems that this happened after the update of OS X 10.10.3.

Wednesday, 26 March 2014

Format date on textbox in Lightswitch HTML client

The HTML client for Ligthswitch is nice, except that not everything is that easy to obtain as in the Silverlight version. So is formatting dates on 'view' screens. Despite setting it at the entity in the 'Server' part of the project, it doesn't show up on the HTML output.
Solution:
Add a 'postRender' script to the date field(s) you like to format.

  • Therefore, go to the (view)screen where you like to format the date.
  • Select the field which shows a date. Let say 'StartDate'.
  • Click on 'Write code' on top of the window and select 'StartDate_postRender'.
  • Add the following piece of code:

myapp.ViewProject.StartDate_postRender = function (element, contentItem) {
    // Write code here.
    contentItem.dataBind("value", function (value) {
        if (value) {
            $(element).text(value.format("dd-MM-yyyy"));
        }
    })
};


Done.

Tuesday, 11 June 2013

Free online 15GB+ storage alternative for Dropbox

Hi folks,

Dropbox is fine, but you can run out of space. There is a free alternative which give you even bigger storage, copy.com!
You start with 15GB and for every user who creates an account via yours, you both get 5 GB storage extra, for free.
So, start creating an account with this link: https://copy.com?r=2ClF1N and get the default 15GB + 5 GB extra, because of using this link (and I get 5 GB free as well :) ).

Copy.com supports both Microsoft and Mac OS X environment!

Thanks and have a nice day!