I'm having a Laravel 5.2 single page app that after rendering in the DOM will fetch some settings via AJAX calls. It is very possible that many ajax calls are done simultaneously.
Sometimes I will receive a 500 error because the table users cannot be found (which does exist). If I extract the query I can see that the used query language is sqlite while my database settings state that it should be sqlsrv. So it seems Laravel is using sqlite as database connection.
Does anyone has any idea on why this happens and what I can do to prevent it?
The database config is:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'acti' => [
'driver' => env('DB_ACTI_DRIVER', 'sqlite'),
'host' => env('DB_ACTI_HOST', null),
'database' => env('DB_ACTI_DATABASE', ':memory:'),
'username' => env('DB_ACTI_USERNAME', null),
'password' => env('DB_ACTI_PASSWORD', null),
'charset' => env('DB_ACTI_CHARSET', 'utf8'),
'prefix' => env('DB_ACTI_PREFIX', ''),
'strict' => false,
'engine' => null,
],
'aspect' => [
'driver' => env('DB_ASPECT_DRIVER', 'sqlite'),
'host' => env('DB_ASPECT_HOST', null),
'database' => env('DB_ASPECT_DATABASE', ':memory:'),
'username' => env('DB_ASPECT_USERNAME', null),
'password' => env('DB_ASPECT_PASSWORD', null),
'charset' => env('DB_ASPECT_CHARSET', 'utf8'),
'prefix' => env('DB_ASPECT_PREFIX', ''),
'strict' => false,
'engine' => null,
],
'navision' => [
'driver' => env('DB_NAVISION_DRIVER', 'sqlite'),
'host' => env('DB_NAVISION_HOST', null),
'database' => env('DB_NAVISION_DATABASE', ':memory:'),
'username' => env('DB_NAVISION_USERNAME', null),
'password' => env('DB_NAVISION_PASSWORD', null),
'charset' => env('DB_NAVISION_CHARSET', 'utf8'),
'prefix' => env('DB_NAVISION_PREFIX', ''),
'strict' => false,
'engine' => null,
]
]
The ajax code is as follows:
$.ajax({
type: 'GET',
dataType: 'json',
url: laroute.route('acti.preference.get', {
pluginName: this.plugin.name,
name: this.name
}),
success: $.proxy(function (data) {
this.updateFromApi(data.value);
if (data.value === undefined) {
this.saveToApi();
}
}, this),
error: function () {
console.log('receive error', arguments);
}
})
The standard connection is 'acti' and the .env holds the correct information.
After some testing I can confirm that the env method does not always return the correct information. I can see that sometimes the default value (which is sqlite) is returned in stead of the actual data in the .env file.