I posted it on WordPress discussion and submitted a ticket as well. The problem is in ms-setting.php file with new way they set $path and $current_site->path variables. In WP 3.8.3 they had
$current_site->path = $path = PATH_CURRENT_SITE;
and in WP 3.9 they set
$current_site->path = PATH_CURRENT_SITE;
and $path is determined by the $_SERVER['REQUEST_URI'] variable. So when you load wp-load.php file inside your application (and wordpress is in subdirectory) you have $path and $current_site->path variable different which ends up in no blog defined case, which gives Database connection error.
Current workaround is to override $_SERVER['REQUEST_URI'] = '/blog/';
before loading wp-load.php
More information can be found:
http://wordpress.org/support/topic/wordpress-39-multisite-db-connection-error https://core.trac.wordpress.org/ticket/27999