Using .NET's DbConnection.GetSchema(), how do I find the owner of a given database?
Alternatively, if you have another solution that is not coupled to a specific impelementation of SQL, I'd like to hear that as well.
Using .NET's DbConnection.GetSchema(), how do I find the owner of a given database?
Alternatively, if you have another solution that is not coupled to a specific impelementation of SQL, I'd like to hear that as well.
The GetSchema call of DbConnection unfortunately doesn't retrieve the DB owner for you :-(
But you can try this on SQL Server:
select
db.name, db.database_id, l.name, l.type
from
sys.databases db
inner join
sys.login_token l on db.owner_sid = l.sid
If you want to connect to SQL Server from .NET, you could use the SMO (SQL Management Objects) and find your owner like this:
Server server = new Server("Your Server");
Database db = server.Databases["Your Database"];
Console.WriteLine("Database owner is: " + db.Owner);
Marc
I don't believe that the SQL-92 standard specifies that a Catalog (a database) must have an owner. As such, I don't know that you can get a non-implementation-specific way of doing this.