// use ordinals to speed up access to DataReader // links: // crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete // docLink: http://sql2x.org/documentationLink/327451c3-64a8-4de8-b359-76742d634497 // parameters: // reader: IDataReader from SQLClient public void Populate(IDataReader reader, DefaultResourceDatabaseStatisticsDataOrdinals ordinals) { if (!reader.IsDBNull(ordinals.ReservedPageCount)) { ReservedPageCount = reader.GetInt32(ordinals.ReservedPageCount); } }
/// <summary>Get default database size</summary> /// <cardinality>Many</cardinality> public List <DefaultResourceDatabaseStatisticsData> DefaultResourceDatabaseStatistics() { var ret = new List <DefaultResourceDatabaseStatisticsData>(); string sql = @" select cast(sum(reserved_page_count) * 8.0 as int) as reserved_page_count from sys.dm_db_partition_stats "; Logging log = Logging.PerformanceTimeStart("Default", "DataAccessLayer", "DefaultSearch", "DefaultResourceDatabaseStatistics"); try { using (var conn = new SqlConnection(Conn.ConnectionString)) { conn.Open(); conn.BeginTransaction(IsolationLevel.ReadUncommitted).Commit(); using (var command = new SqlCommand(sql, conn)) { log.PerformanceTimePrepare(command); IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult); log.PerformanceTimeCheck(); var ordinals = new DefaultResourceDatabaseStatisticsDataOrdinals(reader); while (reader.Read()) { var data = new DefaultResourceDatabaseStatisticsData(); data.Populate(reader, ordinals); ret.Add(data); } reader.Close(); } } } catch (Exception ex) { log.Error(ex); } return(ret); }