Question

I get the following error when trying to select a database with php's standard mssql_select_db function: USE statement is not supported to switch between databases. Use a new connection to connect to a different Database. (severity 16). So i'm stumped as in where to go from here.

Connection Code:

$link = mssql_connect('dsn', 'user@server', 'password');

if (!$link) {
   die('Unable to connect!');
}

if (!mssql_select_db('db', $link)) {
   die('Unable to select database!');
}

$result = mssql_query('SELECT * FROM yourtable');

while ($row = mssql_fetch_array($result)) {
   var_dump($row);
}

My system setup is as follows:

  • Ubuntu 12.10
  • PHP5
  • Apache2
  • freeTDS
  • unixODBC
  • SQL Azure

Also I was following this guide.

Was it helpful?

Solution

In response to @Pondlife's last comment above and since he has not made it an answer I will do it for him until he posts it himself.

@Pondlife comment:

I have no experience with Azure myself, but the error message is very clear: you can't change databases with USE in SQL Azure. I don't know how or if you can prevent your particular client libraries issuing a USE command, but I would try removing the mssql_select_db() call completely and specify the correct database name in your ODBC DSN. Hopefully that will connect you directly to the database you want to use. - PondLife

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top