News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen's Blog:
Retrieving a list of databases from SQL Server
May 20, 2009 @ 08:27:48

Rob Allen (as a part of his work on his WinPHP Challenge entry) has posted a little code snippet to his blog about fetching the list of all databases sitting on a SQL Server instance.

I need to get a list of databases from SQL Server for the currently logged in user. Initially, I found a built in function sp_databases. This looked promising, until I discovered that it didn't work for my user. I'm pretty sure that it's related to permissions. The user just has db_owner on a specific database and nothing else.

He ended up selecting from a sys.database table where the name wasn't in a grouping of standard SQL Server databases (like "master" or "msdb"). He wrapped this in a foreach with a try/catch to catch errors thrown and drops all of the names into a regular array.

0 comments voice your opinion now!
master system list database sqlserver


blog comments powered by Disqus

Similar Posts

Lukas Smith's Blog: Database abstraction mailing list [UPDATE]

Brian Swan's Blog: Troubleshooting and Performance Tuning with SQL Server Traces

Sitecritic.net: Simple Content Management in PHP Without Database Access

DesiznTech.info: 10 Free and Useful IDE for Programmers and Developers

Brian Swan's Blog: PHP Driver for SQL Server - Request for Feature Feedback


Community Events











Don't see your event here?
Let us know!


security threedevsandamaybe series release opinion introduction podcast unittest component composer language hack application hhvm code install framework symfony2 facebook package

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework