Example #1
0
        static void Main(string[] args)
        {
            GetDMV getdmv = new GetDMV();
            InsertDMV insdmv = new InsertDMV();
            string queryString1 = "SELECT * FROM [dbo].[Persons] p WHERE p.BusinessEntityID>2;";
            string queryString2 = "SELECT p.BusinessEntityID FROM [dbo].[Persons] p WHERE p.BusinessEntityID>2;";
            string clearcache = "DBCC FREEPROCCACHE";                // getdmv.StartQuery(clearcache);
            Console.ForegroundColor = ConsoleColor.White;
            CreateTables.TablesCreate();
            getdmv.StartQuery(clearcache);

            // После этого запускать основой цикл по обработке запросов

            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < 2; i++)
                {
                    getdmv.StartQuery(queryString1);
                    getdmv.StartQuery(queryString2);
                }
                getdmv.GetDMVinfo(queryString1, "SELECT", "*", "Persons", "WHERE");
                getdmv.GetDMVinfo(queryString2, "SELECT", "BusinessEntityID", "Persons", "WHERE");
                //getdmv.StartQuery(clearcache);
            }
            insdmv.InsertDMVinfoInAll(getdmv);
            insdmv.InsertDMVinfoInAvg();
            Console.WriteLine("Program Complete. Enter to exit");
            Console.ReadKey();
        }
Example #2
0
        public void InsertDMVinfoInAll(GetDMV getdmv)
        {
            int BoolConnect = 0;
            string connectionString = @"Data Source=(local)\SERVER2012;
                            Initial Catalog=AdventureWorks2012;
                            Integrated Security=True";
            foreach (var s in getdmv.InfoStruct)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    //unsinged long sum = 0;
                    Console.WriteLine((Byte[])s.QueryHash);
                    string HashPlan="";
                    HashPlan = HashPlan + s.QueryHash[0];
                    HashPlan = HashPlan + s.QueryHash[1].ToString();
                    HashPlan = HashPlan + s.QueryHash[2].ToString();
                    HashPlan = HashPlan + s.QueryHash[3].ToString();
                    HashPlan = HashPlan + s.QueryHash[4].ToString();
                    HashPlan = HashPlan + s.QueryHash[5].ToString();
                    HashPlan = HashPlan + s.QueryHash[6].ToString();
                    HashPlan = HashPlan + s.QueryHash[7].ToString();
                    string SetQuery = "DECLARE @BinaryNumber binary(8) " +
                                      "SET @BinaryNumber =  CAST(" + s.QueryHash[0] + " AS binary(1))+CAST(" + s.QueryHash[1] + " AS binary(1))+CAST(" + s.QueryHash[2] + " AS binary(1))+CAST(" + s.QueryHash[3] + " AS binary(1))+" +
                                                           "CAST(" + s.QueryHash[4] + " AS binary(1))+CAST(" + s.QueryHash[5] + " AS binary(1))+CAST(" + s.QueryHash[6] + " AS binary(1))+CAST(" + s.QueryHash[7] + " AS binary(1)) " +
                                     "INSERT INTO dbo.AllQueryTable( CPUTime,ExecTime,QueryText, ObjType, ExecCount, query_plan, query_hash ) " +
                                      "VALUES ( " +
                                          "" + s.CPUTime.ToString() + "," + //
                                          "" + s.CPUTime.ToString() + "," +// "" + s.CPUTime.ToString() + "," +
                                          "'" + s.QueryText + "'," +// "'" + s.QueryText + "'," +
                                          "N'" + s.ObjType + "'," +// "N'" + s.ObjType + "'," +
                                          "" + s.ExecCount + "," +// "" + s.ExecCount + "," +
                                          "'" + s.QueryPlan + "', " +// "'"+ s.QueryPlan + "', " +
                                          "@BinaryNumber" +
                                          ")";

                    // Console.WriteLine(SetQuery);
                    if (BoolConnect == 0)
                    {
                        Console.WriteLine("Insert into All Connection Success \n");
                        BoolConnect++;
                    }
                    SqlCommand command = new SqlCommand(SetQuery, connection);
                    try
                    {
                        connection.Open();
                        SqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {

                        }
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("ExecuteQuery: Status -----> Complete \n");
                        Console.ForegroundColor = ConsoleColor.White;
                        reader.Close();
                    }
                    catch (Exception ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Не удалось выполнить InsertDMVinfoInAll \n");
                        Console.ForegroundColor = ConsoleColor.White;
                    }

                }
            }
        }