diff --git a/product/CMFActivity/ActivityConnection.py b/product/CMFActivity/ActivityConnection.py
index 8241f45bc2448aa2a18d6a8fcfb944986b83699d..75a05d3fe7c8aa06af14862b7b370b83bda4b86f 100644
--- a/product/CMFActivity/ActivityConnection.py
+++ b/product/CMFActivity/ActivityConnection.py
@@ -29,6 +29,7 @@
 from Products.ZMySQLDA.DA import Connection
 from Products.ERP5Type.Globals import InitializeClass
 from App.special_dtml import HTMLFile
+from Acquisition import aq_parent
 
 # If the sort order below doesn't work, we cannot guarantee the setSortKey()
 # call below will actually result in the activity connection being committed
@@ -41,7 +42,7 @@ def manage_addActivityConnection(self, id, title,
                                  connection_string,
                                  check=None, REQUEST=None):
     """Add a DB connection to a folder"""
-    self._setObject(id, Connection(id, title, connection_string, check))
+    self._setObject(id, ActivityConnection(id, title, connection_string, check))
     if REQUEST is not None: return self.manage_main(self,REQUEST)
 
 class ActivityConnection(Connection):
@@ -59,10 +60,13 @@ class ActivityConnection(Connection):
 
     def connect(self, s):
         result = Connection.connect(self, s)
+        if aq_parent(self) is None:
+            # Connection.connect() doesn't set _v_database_connection if there
+            # are no acquisition wrappers
+            return result
         # the call above will set self._v_database_connection, and it won't
         # have disappeared by now.
-        # We need to put back this code as soon as problems are solved XXX
-        #self._v_database_connection.setSortKey( (0,) )
+        self._v_database_connection.setSortKey( (0,) )
         return result
 
 InitializeClass(ActivityConnection)
diff --git a/product/CMFActivity/tests/testCMFActivity.py b/product/CMFActivity/tests/testCMFActivity.py
index be8be0dcf5d7ec7dfbe97dd06ef8f958ec21cf80..28dd8685acdc04cb5c410a0467632bb0c5236e21 100644
--- a/product/CMFActivity/tests/testCMFActivity.py
+++ b/product/CMFActivity/tests/testCMFActivity.py
@@ -3872,6 +3872,8 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
         stdconn.title,
         stdconn.connection_string
     )
+    newconn = portal.cmf_activity_sql_connection
+    self.assertEquals(newconn.meta_type, 'CMFActivity Database Connection')
 
 def test_suite():
   suite = unittest.TestSuite()