Link to home
Start Free TrialLog in
Avatar of Steve
SteveFlag for Australia

asked on

PHP ODBC access (under windows iis) to remote MSSQL database with ApplicationIntent requirement issue.

so.. Im trying to connect to a remote Microsoft SQL Database that requires applicationintent=ReadOnly.

If i setup a local ODBC Data source on my notebook and enable Application Intent to ReadOnly and use 'ANSI quoted identifiers' i can use Access and access the db and run queries access the data no problems.

But.. i need to access this from a PHP script, so i wrote the following :
<?php
    $user = '<username>';
    $pass = '<password>';
    $server = '<remoteMSSQLServer>';
    $database = 'dbname';
    $appintent = 'ReadOnly';

    $connection_string = "DRIVER={SQL Server};SERVER=$server;DATABASE=$database;ApplicationIntent=$appintent";
    $conn = odbc_connect($connection_string,$user,$pass);
if (!$conn){
    if (phpversion() < '4.0'){
      exit("Connection Failed: . $php_errormsg" );
    }
    else{
      exit("Connection Failed:" . odbc_errormsg() );
    }
}
?>

Open in new window


but when i try to browse to it, I only every get :

Connection Failed:[Microsoft][ODBC SQL Server Driver][SQL Server]The target database ('dbname') is in an availability group and is currently accessible for connections when the application intent is set to read only. For more information about application intent, see SQL Server Books Online.

any ideas what ive missed ?

PHP Ver. 5.6.24 running under Windows Server 2012 IIS with

extension=php_pdo_odbc.dll
extension=php_pdo_sqlsrv.dll
extension=php_sqlsrv.dll
 loaded
ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial