Solved

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

Posted on 2016-11-23
2
112 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

738 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