How can I get SQL Server database properties from C# code? -


i've c# 4.0 console application , sql server 2008 database , running on database server.

does know if there way database properties (like "database read-only" ) c# code?

my guess should be, not able find out accurate solution.

thanks in advance

there @ least 2 ways it. 1 use database metadata tables other use sql management objects in both cases there's lot of data there need know want. example how "database read-only" property mentioned.

using sqlcommand against metadata

using (sqlconnection cnn = new sqlconnection("data source=.;initial catalog=master;integrated security=sspi;")) {    sqlcommand cmd = new sqlcommand("select is_read_only sys.filegroups",cnn);    cnn.open();    var isreadonly = cmd.executescalar();    console.writeline(isreadonly ); } 

using smo

using system; using microsoft.sqlserver.management.smo;  namespace smo_test {     class program     {         static void main(string[] args)         {             server srv = new server(); //connection local sql server               database db = srv.databases["master"];             foreach (filegroup fg in db.filegroups)             {                 console.writeline(fg.readonly);              }          }     } } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -