3

Up until yesterday I have been happily connecting to SQL Server Express 2005 using PHP 5 on IIS 7.

Yesterday I started getting errors when selecting a database.

<?php
$link = mssql_connect('localhost,1433', 'login', 'password');

if(!$link) {
    die('could not connect to MSSQL');
}

 if(!mssql_select_db('database', $link)) {
    echo mssql_get_last_message();
    die('could not select db');    
}    
?>

This outputs the following:

"Changed database context to 'database'.could not select db"

So mssql_get_last_message is outputting Changed database context to 'database'. which seems all correct and isn't really an error message. But then the mssql_select_db is still failing.

I have tested the following:

  • The login is correct (you get a different error changing the username or password)
  • The database exists (you get a different error if I use the name of a database that doesn't exist
  • The login can connect to the database (you get a different error if you delete the database user in SQL Server)

I'm not sure what else to test.

4
  • What does select state_desc, user_access_desc from master.sys.databases where name = 'YourDB' return? Commented Sep 30, 2010 at 12:21
  • Hi Martin, thanks for the response - these are the results or your query: state_desc = ONLINE, user_access_desc = MULTI_USER Commented Sep 30, 2010 at 12:42
  • any recent upgrades to anything? SQL Server Express 2005? PHP 5? IIS 7? any server restarts? Commented Sep 30, 2010 at 13:16
  • I'd been detaching, renaming and reattaching some databases just prior to the problems. Commented Sep 30, 2010 at 13:33

1 Answer 1

1

Thanks to Martin and Phil for their responses. I created a new login and a new corresponding user which fixed the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.