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 'username@database.database.windows.net' -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' , 'username@database.database.windows.net', '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

Edited by GavMJM
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.