Index: server/src/akonadi.h
===================================================================
--- server/src/akonadi.h	(wersja 846037)
+++ server/src/akonadi.h	(kopia robocza)
@@ -46,6 +46,8 @@
     AkonadiServer( QObject *parent = 0 );
     ~AkonadiServer();
 
+    bool isValid() const;
+
   public Q_SLOTS:
     /**
      * Triggers a clean server shutdown.
@@ -60,7 +62,7 @@
     void incomingConnection( quintptr socketDescriptor );
 
   private:
-    void startDatabaseProcess();
+    bool startDatabaseProcess();
     void stopDatabaseProcess();
 
     CacheCleaner *mCacheCleaner;
@@ -68,7 +70,8 @@
     QProcess *mDatabaseProcess;
     QList< QPointer<AkonadiConnection> > mConnections;
     AbstractSearchManager *mSearchManager;
-    bool mAlreadyShutdown;
+    bool mAlreadyShutdown : 1;
+    bool mValid : 1;
 };
 
 }
Index: server/src/main.cpp
===================================================================
--- server/src/main.cpp	(wersja 846037)
+++ server/src/main.cpp	(kopia robocza)
@@ -44,16 +44,20 @@
 
     QCoreApplication app( argc, argv );
 
-    Akonadi::AkonadiServer::instance(); // trigger singleton creation
+    if ( !Akonadi::AkonadiServer::instance()->isValid() ) { // trigger singleton creation
+      //! @todo more detailed message
+      qDebug( "Unable to initialize connection to the database server" );
+      return 1;
+    }
 
     if ( !QDBusConnection::sessionBus().registerService( QLatin1String("org.freedesktop.Akonadi") ) ) {
       qDebug( "Unable to connect to dbus service: %s", qPrintable( QDBusConnection::sessionBus().lastError().message() ) );
       return 1;
     }
 
-    app.exec();
+    const int result = app.exec();
 
     Akonadi::AkonadiServer::instance()->quit();
 
-    return 0;
+    return result;
 }
Index: server/src/akonadi.cpp
===================================================================
--- server/src/akonadi.cpp	(wersja 846037)
+++ server/src/akonadi.cpp	(kopia robocza)
@@ -54,12 +54,16 @@
     , mIntervalChecker( 0 )
     , mDatabaseProcess( 0 )
     , mAlreadyShutdown( false )
+    , mValid( true )
 {
     QSettings settings( XdgBaseDirs::akonadiServerConfigFile(), QSettings::IniFormat );
     if ( settings.value( QLatin1String("General/Driver"), QLatin1String( "QMYSQL" ) ).toString() == QLatin1String( "QMYSQL" )
          && settings.value( QLatin1String( "QMYSQL/StartServer" ), true ).toBool() )
-      startDatabaseProcess();
-
+    {
+      mValid = startDatabaseProcess();
+      if ( !mValid )
+        return;
+    }
     s_instance = this;
 
     const QString connectionSettingsFile = XdgBaseDirs::akonadiConnectionConfigFile(
@@ -199,15 +203,16 @@
     return s_instance;
 }
 
-void AkonadiServer::startDatabaseProcess()
+bool AkonadiServer::startDatabaseProcess()
 {
-#ifdef MYSQLD_EXECUTABLE
+#ifndef Q_WS_WIN // We assume that MySQL is running as service on Windows
+# ifdef MYSQLD_EXECUTABLE
   const QString mysqldPath = QLatin1String( MYSQLD_EXECUTABLE );
-#else
+# else
   const QString mysqldPath;
   Q_ASSERT_X( false, "AkonadiServer::startDatabaseProcess()",
               "mysqld was not found during compile time, you need to start a MySQL server yourself first and configure Akonadi accordingly" );
-#endif
+# endif
 
   // create the database directories if they don't exists
   const QString dataDir = XdgBaseDirs::saveDir( "data", QLatin1String( "akonadi/db_data" ) );
@@ -256,36 +261,54 @@
   mDatabaseProcess->start( mysqldPath, arguments );
   if ( !mDatabaseProcess->waitForStarted() )
     qFatal( "Could not start database server '%s'", qPrintable( mysqldPath ) );
+#endif // !Windows
 
+  const QLatin1String initConn( "initConnection" );
   {
-    QSqlDatabase db = QSqlDatabase::addDatabase( QLatin1String( "QMYSQL" ), QLatin1String( "initConnection" ) );
+    QSqlDatabase db = QSqlDatabase::addDatabase( QLatin1String( "QMYSQL" ), initConn );
+//! @todo result
+    if ( !db.isValid() )
+      return false;
+#ifndef Q_WS_WIN
     db.setConnectOptions( QString::fromLatin1( "UNIX_SOCKET=%1/mysql.socket" ).arg( miscDir ) );
+#endif
 
     bool opened = false;
     for ( int i = 0; i < 120; ++i ) {
       opened = db.open();
       if ( opened )
         break;
-      if ( mDatabaseProcess->waitForFinished( 500 ) )
+      if ( mDatabaseProcess && mDatabaseProcess->waitForFinished( 500 ) )
         qFatal( "Database server exited unexpectedly, exit code %d", mDatabaseProcess->exitCode() );
     }
 
     if ( opened ) {
       QSqlQuery query( db );
+      bool ok = true;
       if ( !query.exec( QLatin1String( "USE DATABASE akonadi" ) ) )
-        query.exec( QLatin1String( "CREATE DATABASE akonadi" ) );
+        ok = query.exec( QLatin1String( "CREATE DATABASE akonadi" ) );
 
       db.close();
+      if ( !ok )
+        return false;
     }
   }
 
-  QSqlDatabase::removeDatabase( QLatin1String( "initConnection" ) );
+  QSqlDatabase::removeDatabase( initConn );
+  return true;
 }
 
 void AkonadiServer::stopDatabaseProcess()
 {
-  mDatabaseProcess->terminate();
-  mDatabaseProcess->waitForFinished();
+  if ( mDatabaseProcess ) {
+    mDatabaseProcess->terminate();
+    mDatabaseProcess->waitForFinished();
+  }
 }
 
+bool AkonadiServer::isValid() const
+{
+  return mValid;
+}
+
 #include "akonadi.moc"