Jump to content

Azure Sql - Freetds - Specific Database


GavMJM

Recommended Posts

Hi all,

 

First off, please excuse my ignorance, I've not used PHP before today...

 

I'm trying to connect to an a Microsoft Azure SQL Database (which is a hosted version of SQL 2008) using MSSQL_Connect and FreeTDS. I believe that because of the way Azure works, you *HAVE* to specify a database to connect to.

 

I can run this successfully:

 

tsql -S AZURE -D 'DatabaseName' -U '[email protected]' -P 'password'

 

However, when I try and run this (in PHP), it does not work:

 

<?php

putenv('FREETDS=/etc/freetds.conf');

putenv('FREETDSCONF=/etc/freetds.conf');

if (!$connection = @mssql_connect( 'AZURE' , '[email protected]', 'password')) {

print("Could not connect!");

} else {

print("Connected!");

}

?>

 

My '/usr/local/etc/freetds.conf' looks like this:

 

[AZURE]

host = database.database.windows.net

port = 1433

tds version = 7.2

client charset = UTF-8

encryption = required

 

TSQL -C outputs this:

 

 

Compile-time settings (established with the "configure" script)

Version: freetds v0.91

freetds.conf directory: /etc

MS db-lib source compatibility: yes

Sybase binary compatibility: yes

Thread safety: yes

iconv library: yes

TDS version: 4.2

iODBC: no

unixodbc: yes

SSPI "trusted" logins: no

Kerberos: yes

 

When I run the PHP, I get this in the freetds dump file:

 

net.c:1370:handshake succeeded!!

gssapi.c:215:kerberos name MSSQLSvc/database.database.windows.net:1433

login.c:466:login packet rejected

util.c:156:Changed query state from IDLE to DEAD

util.c:331:tdserror(0xb25da0, 0xc75880, 20002, 0)

dblib.c:7929:dbperror(0xc74d60, 20002, 0)

dblib.c:7981:20002: "Adaptive Server connection failed"

dblib.c:8002:"Adaptive Server connection failed", client returns 2 (INT_CANCEL)

 

Any ideas? I've gone none, so any help would be massively appreciated.

 

Many thanks,

 

GavMJM

Link to comment
https://forums.phpfreaks.com/topic/272189-azure-sql-freetds-specific-database/
Share on other sites

  • 4 weeks later...

Per the following from MSDN try changing your username to username@database. See if that gets you anywhere

For example, if your login was named login1 and the fully qualified name of your SQL Database server is servername.database.windows.net, the username parameter of your connection string should be: login1@servername.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.