Показать сообщение отдельно
Старый 04.07.2018, 17:15   #5  
Logger is offline
Logger
Участник
Лучший по профессии 2015
Лучший по профессии 2014
 
3,875 / 3123 (112) ++++++++++
Регистрация: 12.10.2004
Адрес: Москва
Записей в блоге: 2
Оставлю чтобы было.

Запускает 2 метода (текст ниже).
1-й с параметром RebuildIndexAll.
т.е. в базе модели запускаются хранимки
"exec [dbo].XU_Reindex"
"exec [dbo].XU_Shrink"
"exec [dbo].[XU_ResetHandleIdentity]"

X++:
// Microsoft.Dynamics.AX.Framework.Tools.ModelManagement.ModelStore
internal static void Optimize(SqlConnection connection, AxUtilContext context, OptimizeOption option)
{
	using (SqlCommand sqlCommand = ModelStore.CreateCommand(connection))
	{
		switch (option)
		{
		case OptimizeOption.DisableIndex:
			try
			{
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.CommandText = string.Format(CultureInfo.InvariantCulture, "[dbo].XU_DisableEnableNonClusteredIndexes", new object[0]);
				sqlCommand.Parameters.Add(new SqlParameter("@dbName", connection.Database));
				sqlCommand.Parameters.Add(new SqlParameter("@changeRecoveryModel", 'N'));
				sqlCommand.Parameters.Add(new SqlParameter("@mode", '1'));
				sqlCommand.ExecuteNonQuery();
				goto IL_246;
			}
			catch (SqlException ex)
			{
				context.ReportWarning(ex.Message);
				context.DisplayResult(string.Format(CultureInfo.CurrentCulture, Resources.DisableIndexFailure, new object[0]));
				goto IL_246;
			}
			break;
		case OptimizeOption.RebuildIndex:
			break;
		case OptimizeOption.RebuildIndexAll:
			goto IL_184;
		default:
			goto IL_184;
		}
		try
		{
			sqlCommand.CommandType = CommandType.StoredProcedure;
			sqlCommand.CommandText = string.Format(CultureInfo.InvariantCulture, "[dbo].XU_DisableEnableNonClusteredIndexes", new object[0]);
			sqlCommand.Parameters.Add(new SqlParameter("@dbName", connection.Database));
			sqlCommand.Parameters.Add(new SqlParameter("@changeRecoveryModel", 'Y'));
			sqlCommand.Parameters.Add(new SqlParameter("@mode", '2'));
			sqlCommand.ExecuteNonQuery();
			goto IL_246;
		}
		catch (SqlException ex2)
		{
			context.ReportWarning(ex2.Message);
			context.DisplayResult(string.Format(CultureInfo.CurrentCulture, Resources.EnableIndexFailure, new object[0]));
			goto IL_246;
		}
		IL_184:
		context.DisplayResult(string.Format(CultureInfo.CurrentCulture, Resources.Reorganizing, new object[0]));
		try
		{
			sqlCommand.CommandText = string.Format(CultureInfo.InvariantCulture, "exec [dbo].XU_Reindex", new object[0]);
			sqlCommand.ExecuteNonQuery();
		}
		catch (SqlException ex3)
		{
			context.ReportWarning(ex3.Message);
			context.DisplayResult(string.Format(CultureInfo.CurrentCulture, Resources.ReindexFailure, new object[0]));
		}
		if (connection.State == ConnectionState.Open)
		{
			try
			{
				sqlCommand.CommandText = string.Format(CultureInfo.InvariantCulture, "exec [dbo].XU_Shrink", new object[0]);
				sqlCommand.ExecuteNonQuery();
			}
			catch (SqlException ex4)
			{
				context.ReportWarning(ex4.Message);
				context.DisplayResult(string.Format(CultureInfo.CurrentCulture, Resources.ShrinkFailed, new object[0]));
			}
		}
		IL_246:;
	}
}
X++:
// Microsoft.Dynamics.AX.Framework.Tools.ModelManagement.ModelStore
internal static void ResetHandleIdentity(SqlConnection connection)
{
	using (SqlCommand sqlCommand = ModelStore.CreateCommand(connection))
	{
		sqlCommand.CommandType = CommandType.StoredProcedure;
		sqlCommand.CommandText = "[dbo].[XU_ResetHandleIdentity]";
		sqlCommand.ExecuteNonQuery();
	}
}

Последний раз редактировалось Logger; 04.07.2018 в 17:18.
За это сообщение автора поблагодарили: gl00mie (5), vmoskalenko (1), AlGol (3).