Aug 31, 2023
0
Level 2
SQLSRV + Windows Auth(SSMS)
Hey everyone,
I am trying to get laravel to connect to MSSQL via Windows Credentials, I have everything installed correctly if I run a test SQL and it works perfect. I think the problem might be Windows Authentication thats how the SQL Server is configured.
Can someone help me with some guidance?
Here is the demo script I got and its able to query MS SQL no issues
/* Specify the server and connection string attributes. */
$serverName = "REMOTE_SERVER_IP";
$connectionInfo = array( "Database"=>"NAME");
/* Connect using Windows Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
}
/* Query SQL Server for the login of the user accessing the
database. */
//$tsql = "SELECT CONVERT(varchar(32), SUSER_SNAME())";
$tsql = "SELECT * FROM DB_TABLE";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
/* Retrieve and display the results of the query. */
$row = sqlsrv_fetch_array($stmt);
Here is my env DB section
DB_CONNECTION=sqlsrv
DB_HOST=XXX.XXX.XXX.XXX
DB_PORT=1433
DB_DATABASE=TABLE_NAME
DB_USERNAME=domain\user
DB_PASSWORD=Password
here is the code that I run that is giving me troubles.
dd(DB::select('SELECT * FROM TABLE_NAME'));
I get this error
SQLSTATE[28000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Login failed for user 'domain\user'.
Please or to participate in this conversation.