Can't Query Database With MS SQL Read Only Account?
Hello! I am developing an internal app where the plan was to have 2 MS SQL 2016 database connections. One is our main "app" database and the other database is a LOB application from another vendor we don't want to mess with.
The main app connection works great without any issues.
The LOB database is mission critical and we can't risk a 3rd party app messing with the data. So any access to it from a 3rd party should be read only.
So I created a read only user on that database (public server role with the db_datareader role on the database itself) and added it to the Laravel database config and tried to run a basic select query against that DB. Unfortunately I got a login error: SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'laravel'. (Connection: foundation_sqlsrv, SQL: select * from jobs)
I verified I can run this query with this same account against the same database using SQL Management studio. But in laravel it fails.
Both that app database that works and this LOB database that gets the login failed are on the same MSSQL host (different MS SQL server instances).
Does laravel not allow read only SQL accounts? Or am I doing something wrong?
Edit:
Just to further isolate this as a laravel issue I connected directly to SQL using PDO in my web.php router using the same ENV variables I used in config/database.php and it worked fine:
Route::get('/test', function () {
$hostname = env('DB_HOST_FOUNDATION');
$username = env('DB_USERNAME');
$password = env('DB_PASSWORD');
$dbName = env('DB_DATABASE_FOUNDATION');
$odbc="sqlsrv:Server=$hostname;Database=$dbName;";
$conn = new PDO($odbc, $username, $password);
$query = 'select * from jobs';
$stmt = $conn->query( $query );
//$jobs = DB::connection('foundation_sqlsrv')->select('select * from dbo.jobs');
return inertia('test', $stmt->fetch( PDO::FETCH_ASSOC ));
});
Please or to participate in this conversation.