The most up to date list of databases will be in the database itself. Why not connect to tempdb
as a default database (since you have to connect to something) to start with and then query from master.sys.databases.
select [name] from master.sys.databases
Then you can update your connection string with whatever database is necessary or simply change the db using the ChangeDatabase()
method.
e.g. connection.ChangeDatabase(selectedDB);
You could also connect to master, but I like to keep default connections in tempdb as occasionally people forget to change databases before creating objects. I would rather the junk go into tempdb than master since tempdb is recreated when SQL restarts.