Solved

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

Posted on 2016-11-23
2
90 Views
Last Modified: 2016-12-28
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
0
Comment
Question by:Steve
2 Comments
 
LVL 26

Accepted Solution

by:
EddieShipman earned 500 total points
ID: 41899785
Take a look at this connection string:
Dim SNACODBCConn As New Odbc.OdbcConnection(“Driver={SQL Server Native Client 11.0};server=aglisten;database=ag;trusted_connection=yes;applicationintent=readonly”)

Open in new window

See the difference between yours? Have you tried it like that?
0
 
LVL 12

Assisted Solution

by:Steve
Steve earned 0 total points
ID: 41900071
Yeah your code is VB though.. i need to do it in PHP as i showed.

I cant use Trusted Connetion, as its not.. but i did change the Server type to use the 'SQL Server Native Client 11.0'  and i seem to now have a connection.

I think what the problem was is that the SQL Server Driver doesnt support the 'ApplicationIntent' argument perhaps ?

Steve
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question