데이터베이스보기의 파티션 목록에 대해 SSAS 큐브의 파티션 이름을 검사하는 SSIS 스크립트 작업을 작성하려고합니다. 파티션이 있지만 목록에 없으면 삭제됩니다. 그렇지 않으면 처리됩니다.AMO - foreach 루프를 사용하여 SQL 조회를 기반으로 동적으로 파티션을 분할합니다.
는 스크립트가 지금까지 파티션 로 작업 표시이 삭제됩니다 , 그러나 그것은 루프를 계속할 수 없습니다 표시하고 다음과 같이 드롭 열거 오류가 발생 :
실행을 대신 스크립트 (예 : rowCount == 1
및 pt.Process()
이없고 else
이없는 경우)가 제대로 작동하고 오류없이 완료됩니다. 파티션을 반복하면서 파티션을 삭제할 수없는 것으로 보입니다. 포인터가 SQL 조회 테이블에서 발견되면이 파티션을 삭제하는 방법에 대해 고맙게 생각합니다.
public void Main()
{
try
{
String Server = Dts.Variables["User::Connection"].Value.ToString();
String Cube = "CubeName";
String conn = "Provider=MSOLAP;Data Source=" + Server + ";";
Server MDXServer = new Server();
MDXServer.Connect(conn);
foreach (Database db in MDXServer.Databases)
{
foreach (Cube cb in db.Cubes)
{
if (cb.Name == Cube)
{
foreach (MeasureGroup mg in cb.MeasureGroups)
{
foreach (Partition pt in mg.Partitions)
{
string PartName = (pt.Name.ToString());
//Create SQL query to reference the parition view and check row count when partition name used in predicate:
string sqlString = "SELECT COUNT(*) FROM [dim].[Partitions] WHERE [FinWeek] = @pt;";
// Open DB connection:
ConnectionManager cm;
cm = Dts.Connections["FIP_Server_Alias"];
SqlConnection connection = (SqlConnection)cm.AcquireConnection(Dts.Transaction);
// Link the query and the connection string together as a command
SqlCommand cmd = new SqlCommand(sqlString, connection);
// Add a value to the parameter in the SQL query
cmd.Parameters.AddWithValue("@pt", PartName);
// Activate reader to read the resulting data set from the query
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) //while loop performs an action whilst the reader is open
{
// Put the second result of query (0 woudl be first) into a string variable in the script task
string rowCount = reader[0].ToString();
//if the partition exists but is not in the database dim.Partitions view, drop from collection.
if (rowCount == "0")
{
pt.Drop();
}
}
//End the read loop
reader.Close();
}
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Dts.TaskResult = (int)ScriptResults.Success;
}
감사합니다. 지금 가지고있는 문제는 컬렉션이 서버 객체에 연결되어 있지 않다는 것입니다. 원래의 질문에 수정 된 코드가 있습니다. – TJB
정확히 말하자면, 'partitions' 콜렉션을 반복해야하고 큐브/측정 값 그룹에 연결해야하는 각 구성원에 대해 해당 특정 파티션에 대한 "연결"참조를 작성한 다음 삭제하십시오. –
코드를 다시 편집하여 서버 연결 오류가 발생했습니다. 내 구문을보고 내가 잘못 가고있는 것을 지적 해 주시겠습니까? 다시 한번 감사드립니다. – TJB