[성현모] TRA Extract
This commit is contained in:
76
CPXV2 TRA JSON/SystemX.Product.CP.TRA.Extract/DBService.cs
Normal file
76
CPXV2 TRA JSON/SystemX.Product.CP.TRA.Extract/DBService.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SystemX.Product.CP.TRA.Extract
|
||||
{
|
||||
|
||||
public class DBService
|
||||
{
|
||||
private string connectionString = "Server=192.168.0.69;Database=CPXV2ShortTermLogJson;User Id=Alis;Password=Kefico!@34;";
|
||||
|
||||
public void GetLargeData()
|
||||
{
|
||||
// 1. 연결 생성
|
||||
using (SqlConnection conn = new SqlConnection(connectionString))
|
||||
{
|
||||
try
|
||||
{
|
||||
// 2. 실행할 쿼리 작성 (JOIN 포함)
|
||||
string sql = @"SELECT [TestListFileNo]
|
||||
,[StepID]
|
||||
,[StepVersion]
|
||||
,[StepDesc]
|
||||
,[SpecMin]
|
||||
,[SpecMax]
|
||||
,[Dim]
|
||||
FROM [CPXV2].[dbo].[VRFY_TestListFileRelease] where StepDesc like 'an10_off' order by testlistfileno";
|
||||
|
||||
SqlCommand cmd = new SqlCommand(sql, conn);
|
||||
// 타임아웃 설정 (600만 건은 시간이 걸릴 수 있으므로 0(무제한) 또는 넉넉하게 설정)
|
||||
cmd.CommandTimeout = 300;
|
||||
conn.Open();
|
||||
|
||||
// 3. DataReader로 데이터 읽기
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
// 예: 데이터 처리 로직
|
||||
var val = Decompression(reader["LogData"].ToString());
|
||||
}
|
||||
}
|
||||
|
||||
//sql = @"SELECT * FROM HIST_LogSummary_2025 as Summary with(nolock) JOIN HIST_TestResult_2025 as Result with(nolock) ON Summary.No = Result.No";
|
||||
}
|
||||
catch (SqlException ex)
|
||||
{
|
||||
Console.WriteLine("DB 오류 발생: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string Decompression(string compressedDataStr)
|
||||
{
|
||||
string result = null;
|
||||
byte[] buffer = Convert.FromBase64String(compressedDataStr);
|
||||
using (MemoryStream stream = new MemoryStream(buffer))
|
||||
{
|
||||
using (GZipStream stream2 = new GZipStream(stream, CompressionMode.Decompress))
|
||||
{
|
||||
using (StreamReader streamReader = new StreamReader(stream2))
|
||||
{
|
||||
result = streamReader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user