Exemplo n.º 1
0
        /// <summary>
        /// Gets the database index usage.
        /// </summary>
        /// <param name="database">The database.</param>
        /// <returns>the database index usage</returns>
        public List <DatabaseIndexUsage> GetDatabaseIndexUsage(string database)
        {
            this.ExecuteUseDatabase(database);

            List <DatabaseIndexUsage> results = new List <DatabaseIndexUsage>();
            DatabaseIndexUsage        resultrow;
            string sqlString = DatabaseIndexUsage.SqlStatement();

            sqlString = string.Format("EXEC sp_executesql @statement = N'{0}'", sqlString.Replace("'", "''"));

            using (SqlConnection connection = new SqlConnection(this.ConnectionString))
                using (SqlCommand command = new SqlCommand(sqlString, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            resultrow = new DatabaseIndexUsage(
                                reader.GetString(reader.GetOrdinal("Schema")),
                                reader.GetString(reader.GetOrdinal("Table")),
                                reader.GetString(reader.GetOrdinal("Index")),
                                reader.GetInt64(reader.GetOrdinal("Reads")),
                                reader.GetInt64(reader.GetOrdinal("Writes")));

                            results.Add(resultrow);
                        }
                    }

                    connection.Close();
                }

            return(results);
        }
        public string SqlStatement()
        {
            string result = DatabaseIndexUsage.SqlStatement();

            return(result);
            // TODO: add assertions to method DatabaseIndexUsageTest.SqlStatement()
        }