0
열 이름과 데이터가 포함 된 위치에 두 개의 텍스트 파일이 있습니다.여러 파일을 여러 테이블에로드하십시오.
텍스트 파일은 데이터베이스에 작성된 두 개의 빈 테이블에 따라 이름이 지정됩니다.
해당 텍스트 파일의 데이터를 데이터베이스의 각 테이블에로드하려면 스크립트 태스크를 사용했지만 ssis 패키지는 실행시 런타임 오류를 발생 시켰습니다.
이 상황의 해결 방법이나 해결 방법을 알려 주시면 감사하겠습니다. 내가 필요한 스크린 샷과 아래의 코드를 제공하고
: -
스크립트 작업 코드 :
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
// TODO: Add your code here
SqlConnection myADONETConnection = new SqlConnection();
myADONETConnection = (SqlConnection)(Dts.Connections["ADO_TestDB"].AcquireConnection(Dts.Transaction) as SqlConnection);
// MessageBox.Show(myADONETConnection.ConnectionString, "ADO_TestDB");
//Reading file names one by one
string SourceDirectory = Dts.Variables["User::VarFolderPath"].Value.ToString();
// TODO: Add your code here
string[] fileEntries = Directory.GetFiles(SourceDirectory);
foreach (string fileName in fileEntries)
{
// do something with fileName
// MessageBox.Show(fileName);
string columname = "";
//Reading first line of each file and assign to variable
System.IO.StreamReader file2 =
new System.IO.StreamReader(fileName);
string filenameonly = (((fileName.Replace(SourceDirectory, "")).Replace(".txt", "")).Replace("\\", ""));
file2.Close();
//Writing Data of File Into Table
int counter = 0;
string line;
System.IO.StreamReader SourceFile =
new System.IO.StreamReader(fileName);
while ((line = SourceFile.ReadLine()) != null)
{
if (counter == 0)
{
columname = line.ToString();
}
else
{
string query = "Insert into dbo." + filenameonly + "(" + columname + ") VALUES('" + line.Replace(",", "','") + "')";
//MessageBox.Show(query.ToString());
SqlCommand myCommand1 = new SqlCommand(query, myADONETConnection);
myCommand1.ExecuteNonQuery();
}
counter++;
}
SourceFile.Close();
}
Dts.TaskResult = (int)ScriptResults.Success;
}
#region ScriptResults declaration
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
}
오류 :