c# - Track Database Status Change sql server -


i want track database status changed in sql server . in solution ,i have database offline due restore primary server . want hint in application(c#) when database offline , when online. (like sql notification event) . .

one way check state of database using timer application

 private void timer1_tick(object sender,eventargs e)     {     if(checkdatabasestate() == "online")        messagebox.show("db online");     else     messagebox.show("db not online");     }      public string checkdatabasestate()     {         string constr = @"data source=.\sqlexpress;integrated security=true;initial catalog=master;";           string sql = string.format("select name, state_desc sys.databases name = '{0}'", dbname);                       sqlconnection conn;                 sqlcommand comm;                 sqldataadapter adapter;                 dataset ds = new dataset();                  conn = new sqlconnection(constr);                 comm = new sqlcommand(sql, conn);                 adapter = new sqldataadapter(comm);                 adapter.fill(ds);                  return ds.tables[0]["state_desc"].tostring();     } 

let me know if helps,


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -