?
Solved

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

Posted on 2016-11-23
2
Medium Priority
?
154 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

765 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