Sunday 9 February 2014

Mendix and SQL Server: Initializing the ConnectionBus failed

After installing Mendix and SQL Server it happens most of the time that running a mendix application the following message appears:
Message: Initializing the ConnectionBus failed.
Cause: Error on initializing database connection.
Stack trace: com.mendix.m2ee.api.AdminException: Initializing the ConnectionBus failed.
at com.mendix.core.MxRuntime.H(SourceFile:472)
Caused by: n: Error on initializing database connection.
at bz.b(SourceFile:218)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

You need to start "SQL Server Configuration Manager"
Go to Start --> Microsoft SQL Server --> Configuration Tools --> SQL Server Configuration Manager

When it opens go to "SQL Server Configuration Manager" --> "SQL Server Network Configuration" --> "Protocols for SQLExpress".

  1. Where you'll find the Protocol TCP/IP, if disabled then Enable it.
  2. Double click on TCP/IP, You'll find its properties and select the "IP Address" tab. In this tab Remove All the TCP Dynamic Ports and add value 1433 to all TCP Port
  3. Restart your SQL Server via "SQL Server Services" --> "SQL Server" --> Restart

Change TCP/IP Disabled to Enabled

Set TCP Dynamic Ports to 0 and TCP Port to 1433

After this, the Mendix application can be started.

Tuesday 4 February 2014

Mendix performance optimization for batch processing.

For some projects we needed to do batch updates or clone records.With Mendix 4, there is the possibility to commit a list entity objects.By using this feature it will improve the performance a lot.

In Mendix 3 it is done like the picture below.

Clone item without optimization

Note: In Mendix 3 it is not possible to create and update attributes at the same time, two activities are needed.
Explanation of the Microflow steps above. This example is limited to process 1000 records.
  1. Retrieve 1000 records
  2. For every record
    1. Create new record including update attributes, commit and refresh.



With Mendix 4, this can be improved. Performance improvement of 50% can be reached.

Explanation of the Microflow steps above. This example is limited to process 1000 records.
  1. Create a empty list
  2. Retrieve 1000 records
  3. For every record
    1. Create new record including update attributes (no commit and no refresh)
    2. Add new record to the list
  4. Finally commit the list including refresh.
    1. Refresh is needed when data needs to be displayed within screen.

In the example above the duration went from 9 seconds to 3.5 seconds.

When much more records needs to be processed it is advised to do it in batches. This can be done by setting the limit and offset at retrieve of the database entity. After the list is commited, clean the list and retrieve a new set of records from the database (see second activity in the Microflow).
Processing too many records at the same time can give memory overflow errors.

tip: When you have entities with more than 10 attributes it could be useful to use the Java clone function within the community commons from Mendix the App Store.