Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

and again: SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Bei der Konvertierung eines nvarchar-Datentyps in einen datetime-Datentyp liegt der Wert außerhalb des gültigen Bereichs. #4677

Closed
FrankWarius opened this issue Dec 22, 2022 · 6 comments

Comments

@FrankWarius
Copy link

SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Bei der Konvertierung eines nvarchar-Datentyps in einen datetime-Datentyp liegt der Wert außerhalb des gültigen Bereichs. (SQL: insert into [wt2212_session] ([session_id], [session_time], [user_id], [ip_address], [session_data]) values (57mhpi06rdmtgi4oudl7gqotum, 2022-12-22 16:21:15, 0, 127.0.0.1, initiated|b:1;))

#0 D:\GitRepos\fisharebest\webtrees\vendor\illuminate\database\Connection.php(720): Illuminate\Database\Connection->runQueryCallback('insert into [wt...', Array, Object(Closure))
#1 D:\GitRepos\fisharebest\webtrees\vendor\illuminate\database\Connection.php(546): Illuminate\Database\Connection->run('insert into [wt...', Array, Object(Closure))
#2 D:\GitRepos\fisharebest\webtrees\vendor\illuminate\database\Connection.php(498): Illuminate\Database\Connection->statement('insert into [wt...', Array)
#3 D:\GitRepos\fisharebest\webtrees\vendor\illuminate\database\Query\Builder.php(3218): Illuminate\Database\Connection->insert('insert into [wt...', Array)
#4 D:\GitRepos\fisharebest\webtrees\app\SessionDatabaseHandler.php(100): Illuminate\Database\Query\Builder->insert(Array)
#5 [internal function]: Fisharebest\Webtrees\SessionDatabaseHandler->write('57mhpi06rdmtgi4...', 'initiated|b:1;')
#6 D:\GitRepos\fisharebest\webtrees\app\Session.php(146): session_regenerate_id(false)
#7 D:\GitRepos\fisharebest\webtrees\app\Auth.php(189): Fisharebest\Webtrees\Session::regenerate()

@FrankWarius
Copy link
Author

see https://laravel.io/forum/sql-server-date-format-issue

Change Default Language of MS SQL Database User (from DE-DE) to EN-US solves the issue
Should we add a check of DB-User Language to the setup script or are there other possibilities?

@fisharebest
Copy link
Owner

Should we add a check of DB-User Language to the setup script

This documentation says that we can select a language for the current session/transaction;

https://database.guide/how-to-set-the-current-language-in-sql-server-tsql/

if (DB::connection()->getDriverName() === 'sqlsrv') {
  DB::connection()->unprepared('SET language en-us'); // For timestamp columns
}

We could do this here:

Maybe also needed here:

or are there other possibilities?

We could replace the TIMESTAMP columns with INTEGER, and store unix timestamps directly...?

@FrankWarius
Copy link
Author

i found this here https://stackoverflow.com/questions/34616869/set-database-connection-and-language-dynamically-in-laravel and adjusted it slightly:

You can easily do that with a middleware - see some docs here: https://laravel.com/docs/master/middleware

You need a middleware that would be run for all requests before controllers are executed. This middleware should configure application locale and connection used based on the domain and then execute the request. Something similar to the following logic should do the trick:

public function handle($request, Closure $next)
{
$language = "us_english";
//set connection used
Config::set('database.default', $language);
//set application locale
App::setLocale($language);

return $next($request); }
not sure that we need set local

@FrankWarius
Copy link
Author

@ -106,6 +106,10 @@ class UseDatabase implements MiddlewareInterface
'foreign_key_constraints' => true,
]);

    if (DB::connection()->getDriverName() === 'sqlsrv') {
        DB::connection()->unprepared('SET language en-us'); // For timestamp columns
    }

    $capsule->setAsGlobal();

    try {

to early Exception null Connection

@fisharebest
Copy link
Owner

to early Exception null Connection

I think this code should go after the line $capsule->setAsGlobal();

@FrankWarius
Copy link
Author

yes it works
@ -115,6 +115,10 @@ class UseDatabase implements MiddlewareInterface
throw new RuntimeException($exception->getMessage());
}

    if ($driver === 'sqlsrv') {
        DB::connection()->unprepared('SET language us_english'); // For timestamp columns
    }

    return $handler->handle($request);
}

}
still fighting with github :-) Can you add?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants