MetaData_model_package

2011011414402480.png

 

 

中间DFT_DATA 根据条件而变动

SCR_CNF的脚本为

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace ST_f2fae4c9cab446c588a765c3131803fe.csproj
{
[System.AddIn.AddIn(
" ScriptMain " , Version = " 1.0 " , Publisher = "" , Description = "" )]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

#region VSTA generated code
enum ScriptResults
{
Success
= Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure
= Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion

/*
The execution engine calls this method when the task executes.
To access the object model, use the Dts property. Connections, variables, events,
and logging features are available as members of the Dts property as shown in the following examples.

To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
To post a log entry, call Dts.Log("This is my log text", 999, null);
To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);

To use the connections collection use something like the following:
ConnectionManager cm = Dts.Connections.Add("OLEDB");
cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";

Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

To open Help, press F1.
*/

public void Main()
{
// TODO: Add your code here
#region MyRegion
// Dim sqlReader As SqlDataReader

// Dim sqlConn As New SqlClient.SqlConnection("Data Source=192.168.1.214;Initial Catalog=ETLMetaData;User ID=ETLBI_User;Password=123!@#abc")

// Dim cmd As New SqlCommand("SELECT Status,Db from dbo.etl_configure where id=143 ", sqlConn)

// sqlConn.Open()

// sqlReader = cmd.ExecuteReader()


// Do While sqlReader.Read
// Dts.Variables("Status").Value = sqlReader.Item("Status")
// Dts.Variables("DB").Value = sqlReader.Item("DB")
// Loop

// sqlConn.Close()

// MsgBox(Dts.Variables("Status").Value)

// MsgBox(Dts.Variables("DB").Value)
#endregion

// system packagename variabales
string PackageName = Dts.Variables[ " PackageName " ].Value.ToString();
//
string OnlineServerIP = "" ;
string OnlineMainDB = "" ;
string BackServerIp = "" ;
string BackDB = "" ;
Int32 Isenable;


// MessageBox.Show(Dts.Variables["PackageName"].Value.ToString());
// try
// {
System.Data.SqlClient.SqlConnection conn
= new System.Data.SqlClient.SqlConnection
(
" Data Source=192.***.*.***;Initial Catalog=ETLMetaData;User ID=ETLBI_User;Password=****** " );

System.Data.SqlClient.SqlCommand cmd
= new System.Data.SqlClient.SqlCommand(
(
" SELECT Status,OnlineServerIP,OnlineMainDB,Tabname,BackServerIp,BackDB,Condition,Isenable,TargetServerIp,TargetDB,TargetTabname from dbo.ETL_MetaData where PackageName=' "
+ PackageName + " ' " ), conn);

conn.Open();

System.Data.SqlClient.SqlDataReader reader
= cmd.ExecuteReader();


while (reader.Read())
{

// get variables
Dts.Variables[ " Status " ].Value = reader.GetInt32( 0 );
OnlineServerIP
= reader.GetString( 1 );
OnlineMainDB
= reader.GetString( 2 );
Dts.Variables[
" TabName " ].Value = reader.GetString( 3 );
BackServerIp
= reader.GetString( 4 );
BackDB
= reader.GetString( 5 );
Dts.Variables[
" Condition " ].Value = reader.GetString( 6 );
Isenable
= reader.GetInt32( 7 );
Dts.Variables[
" TargetServerIP " ].Value = reader.GetString( 8 );
Dts.Variables[
" TargetDB " ].Value = reader.GetString( 9 );
Dts.Variables[
" TargetTabname " ].Value = reader.GetString( 10 );


}

conn.Close();
cmd.Dispose();

// status =2
if ( int .Parse(Dts.Variables[ " Status " ].Value.ToString()) == 2 )
{
Dts.Variables[
" ServerIp " ].Value = OnlineServerIP;
Dts.Variables[
" DB " ].Value = BackDB;
}

// status =1
if ( int .Parse(Dts.Variables[ " Status " ].Value.ToString()) == 1 )
{
Dts.Variables[
" ServerIp " ].Value = BackServerIp;
Dts.Variables[
" DB " ].Value = BackDB;
}

// status =3
if ( int .Parse(Dts.Variables[ " Status " ].Value.ToString()) == 3 )
{
Dts.Variables[
" ServerIp " ].Value = OnlineServerIP;
Dts.Variables[
" DB " ].Value = OnlineMainDB;
}

Dts.Variables[
" LogDB " ].Value = OnlineMainDB;


// MessageBox.Show(Dts.Variables["Status"].Value.ToString());
// MessageBox.Show(Dts.Variables["DB"].Value.ToString());
// MessageBox.Show(Dts.Variables["ServerIp"].Value.ToString());
// MessageBox.Show(Dts.Variables["LogDB"].Value.ToString());

// }
// catch (Exception ex)
// {
// Dts.TaskResult = (int)ScriptResults.Failure;

// throw;
// }

Dts.TaskResult
= ( int )ScriptResults.Success;
}
}
}

 

scr_I的脚本为

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ST_e4c1a520328d4f4aa4c9b254a7100d9e.csproj
{
[System.AddIn.AddIn(
" ScriptMain " , Version = " 1.0 " , Publisher = "" , Description = "" )]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

#region VSTA generated code
enum ScriptResults
{
Success
= Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure
= Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion

/*
The execution engine calls this method when the task executes.
To access the object model, use the Dts property. Connections, variables, events,
and logging features are available as members of the Dts property as shown in the following examples.

To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
To post a log entry, call Dts.Log("This is my log text", 999, null);
To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);

To use the connections collection use something like the following:
ConnectionManager cm = Dts.Connections.Add("OLEDB");
cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";

Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

To open Help, press F1.
*/

public void Main()
{
// TODO: Add your code here

System.Data.SqlClient.SqlConnection conn
= new System.Data.SqlClient.SqlConnection
(
" Data Source=192.***.*.***;Initial Catalog=ETLMetaData;User ID=ETLBI_User;Password=******* " );

System.Data.SqlClient.SqlCommand cmd
= new System.Data.SqlClient.SqlCommand(
(
" SELECT count(1) as num,getdate() as Bdate from dbo.etl_status where status=1 and [date]= cast(getdate()-1 as date) and db=' "
+ Dts.Variables[ " LogDB " ].Value + " ' and tabname=' " + Dts.Variables[ " TabName " ].Value + " ' "
), conn);

conn.Open();

System.Data.SqlClient.SqlDataReader reader
= cmd.ExecuteReader();

while (reader.Read())
{

// get variables
Dts.Variables[ " i " ].Value = reader.GetInt32( 0 );
Dts.Variables[
" BDate " ].Value = reader.GetDateTime( 1 );

}

conn.Close();
cmd.Dispose();


// MessageBox.Show("SELECT count(1) as num,getdate() as Bdate from dbo.etl_status where [date]= cast(getdate()-1 as date) and db='" + Dts.Variables["LogDB"].Value + "' and tabname='" + Dts.Variables["TabName"].Value + "'");
// MessageBox.Show(Dts.Variables["BDate"].Value.ToString());
// MessageBox.Show(Dts.Variables["i"].Value.ToString());
Dts.TaskResult = ( int )ScriptResults.Success;
}
}
}

SCR_LOG 脚本

 

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;

namespace ST_c189490f68984b1b8d5ec8e6546de2e3.csproj
{
[System.AddIn.AddIn(
" ScriptMain " , Version = " 1.0 " , Publisher = "" , Description = "" )]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{

#region VSTA generated code
enum ScriptResults
{
Success
= Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure
= Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion

/*
The execution engine calls this method when the task executes.
To access the object model, use the Dts property. Connections, variables, events,
and logging features are available as members of the Dts property as shown in the following examples.

To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
To post a log entry, call Dts.Log("This is my log text", 999, null);
To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);

To use the connections collection use something like the following:
ConnectionManager cm = Dts.Connections.Add("OLEDB");
cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";

Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

To open Help, press F1.
*/

public void Main()
{
// TODO: Add your code here
System.Data.SqlClient.SqlConnection conn
= new System.Data.SqlClient.SqlConnection
(
" Data Source=192.***.*.***;Initial Catalog=ETLMetaData;User ID=xuwangjin;Password=******* " );

/* System.Data.SqlClient.SqlCommand cmd
= new System.Data.SqlClient.SqlCommand(
("SELECT count(1) as num,getdate() as Bdate from dbo.etl_status where [date]= cast(getdate()-1 as date) and db='"
+ Dts.Variables["LogDB"].Value + "' and tabname='" + Dts.Variables["TabName"].Value + "'"
), conn);
*/

System.Data.SqlClient.SqlCommand cmd
= new System.Data.SqlClient.SqlCommand(
(
" insert into etl_status(db,tabname,date,datacount,etlcount,bdate,edate,status) select ' "
+ Dts.Variables[ " LogDB " ].Value + " ',' " + Dts.Variables[ " TabName " ].Value + " ',cast(getdate()-1 as date), " + Dts.Variables[ " ResourceDataCount " ].Value + " , " + Dts.Variables[ " TargetDataCount " ].Value + " ,' " + Dts.Variables[ " BDate " ].Value + " ',getdate() " + " ,1 "
), conn);


conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();


/* MessageBox.Show(" insert into etl_status(db,tabname,date,datacount,etlcount,bdate,edate,status) select '"
+ Dts.Variables["LogDB"].Value + "','" + Dts.Variables["TabName"].Value + "',cast(getdate()-1 as date)," + Dts.Variables["ResourceDataCount"].Value + "," + Dts.Variables["TargetDataCount"].Value + ",'" + Dts.Variables["BDate"].Value + "',getdate()" +",1"
);

*/
// MessageBox.Show(Dts.Variables["BDate"].Value.ToString());
// MessageBox.Show(Dts.Variables["EDate"].Value.ToString());
// MessageBox.Show(Dts.Variables["i"].Value.ToString());
Dts.TaskResult = ( int )ScriptResults.Success;
}
}
}

 

SCR_CNF 用于MetaData 配置信息根据配置表决定源头server 和db 利于备库的迁移和ETL的维护.

scr_I  用于ETL log验证

SCR_LOG 记录 Log

DFT_DATA 也是最关键的根据配置表的条件实现动态条件处理和 动态mapping.

下面是这个模板包牵涉到的变量

 

 

 

2011011414545819.png

 

MetaDATA ETL 基本告一段落.后续注重优化DFT_DATA

转载于:https://www.cnblogs.com/xwj1985/archive/2011/01/14/1935592.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值