Solved

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

Posted on 2016-11-23
2
42 Views
Last Modified: 2016-11-27
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to validate 2 forms at once 8 27
html input clean up 3 32
Codiing Non-Existent Links 4 30
Setting Up Local Lan Web Server 1 18
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now