每个数据源的连接字符串,即Excel,OLE DB等都保存在SQL表中。我们需要一次拉出每个连接字符串然后读取相应的数据源(Flat文件,excel,OLE DB),检查记录数并在目标SQL表中加载它们。虽然我在SSIS中尝试了foreach循环容器,但它适用于OLEDB,不适用于Excel,平面文件。
try
{
int IsActive = Convert.ToInt32(Dts.Variables["User::IsActive"].Value);
String Table = Dts.Variables["User::SourceTable"].Value.ToString();
String ConnString = Dts.Variables["User::ConnString"].Value.ToString();
if (IsActive == 1)
{
string SQL = "SELECT '" + Table + "' AS TableName, N'" + ConnString + "' AS ConnString, COUNT (*) AS RecordCount, GETDATE() AS ActionTime FROM " + Dts.Variables["User::SourceTable"].Value.ToString() + " (NOLOCK)";
Dts.Variables["User::Query"].Value = SQL;
Dts.TaskResult = (int)ScriptResults.Success;
}
}
catch (Exception ex)
{
;
}