0

I'm trying to connect to a SQL server database using larval but when I tried to test I keep getting this error I tried many many solutions.

SQLSTATE[28000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Failed to log on user 'slim'. (SQL: SELECT * FROM names) (View: C:\xampp\htdocs\laravel\pointeur\resources\views\welcome.blade.php)

  • I've created a simple Model :

    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    
    class Record extends Model
    {
        protected $table = 'names';
    }
    
  • with a simple query

                $records = Record::all();
    
                foreach ($records as $record) {
                    echo $record->name;
                }
            ?>
    
  • database.php

    'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', 'DESKTOP-ILM6T0L\SQLEXPRESS1'),
            'database' => env('DB_DATABASE', 'a11'),
            'username' => env('DB_USERNAME', 'ismail'),
            'password' => env('DB_PASSWORD', 'root'),
            'charset' => 'utf8',
            'prefix' => '',
            ],
    
  • .env file

    DB_CONNECTION=sqlsrv
    DB_HOST=DESKTOP-ILM6T0L\ISMAIL
    DB_PORT=3306
    DB_DATABASE=a11
    DB_USERNAME=slim
    DB_PASSWORD=root
    

(I created a user 'slim' with password 'root' )

Db name a11 it has 1 table 'names' with 1 column 'names'.

Help please I just want to connect laravel project with sql server :p

5
  • you have two different usernames which one is correct?? Commented Sep 13, 2017 at 18:21
  • slim is the correct one Commented Sep 13, 2017 at 18:31
  • ok check my answer Commented Sep 13, 2017 at 18:34
  • When you created the user slim, did you specify the correct host to go with that user? Generally for development, it's okay to use % as the host which would allow the user slim to connect from anywhere. Commented Sep 13, 2017 at 21:17
  • Please accept the answer or post your answer to close the question thanks :) stackoverflow.com/help/someone-answers Commented Sep 22, 2017 at 5:50

2 Answers 2

1

If you have defined everything in .env then you don't need to redefining the values in any file like in your database.php

'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', ''),
        'database' => env('DB_DATABASE', ''),
        'username' => env('DB_USERNAME', ''),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
        ],
Sign up to request clarification or add additional context in comments.

Comments

0

You can fix these issues using your .env file found in your root. Provide it with all your database credentials like so.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=afin
DB_USERNAME=homestead
DB_PASSWORD=secret

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.