File name
Commit message
Commit date
File name
Commit message
Commit date
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.OleDb;
namespace SignusKHSVR
{
public class U3Database
{
private OleDbConnection mCN = null;
private OleDbCommand mCmd = null;
public bool SetSqlServer()
{
try
{
mCN = new OleDbConnection();
mCN.ConnectionString = U3Config.m_SqlConnStr;
mCN.Open();
return true;
}
catch (Exception ex)
{
U3Util.ErrorLog("Can't connect to database." + Environment.NewLine + ex.Message);
return false;
}
}
public DataTable OpenSQL(string strSQL)
{
DataTable retTable = new DataTable();
try
{
mCN = new OleDbConnection();
mCN.ConnectionString = U3Config.m_SqlConnStr;
mCN.Open();
mCmd = new OleDbCommand(strSQL, mCN);
OleDbDataAdapter da = new OleDbDataAdapter(mCmd);
da.Fill(retTable);
}
catch (Exception ex)
{
U3Util.ErrorLog(strSQL);
U3Util.ErrorLog(ex.Message);
}
finally
{
if (mCN != null) mCN.Close();
}
return retTable;
}
public DataSet OpenSQLSet(string strSQL)
{
DataSet retTable = new DataSet();
try
{
mCN = new OleDbConnection();
mCN.ConnectionString = U3Config.m_SqlConnStr;
mCN.Open();
mCmd = new OleDbCommand(strSQL, mCN);
OleDbDataAdapter da = new OleDbDataAdapter(mCmd);
da.Fill(retTable);
}
catch (Exception ex)
{
U3Util.ErrorLog(strSQL);
U3Util.ErrorLog(ex.Message);
}
finally
{
if (mCN != null) mCN.Close();
}
return retTable;
}
public int ExcuteSql(string strSql)
{
try
{
mCN = new OleDbConnection();
mCN.ConnectionString = U3Config.m_SqlConnStr;
mCN.Open();
mCmd = new OleDbCommand(strSql, mCN);
int iResult = mCmd.ExecuteNonQuery();
return iResult;
}
catch (Exception ex)
{
U3Util.ErrorLog(strSql);
U3Util.ErrorLog(ex.Message);
return 0;
}
finally
{
if (mCN != null) mCN.Close();
}
}
public bool ExcuteSqls(List<string> strSqls)
{
string strMsg = "";
return ExcuteSqls(strSqls, out strMsg);
}
public bool ExcuteSqls(List<string> strSqls, out string strMessage)
{
string strSQL = string.Empty;
try
{
mCN = new OleDbConnection();
mCN.ConnectionString = U3Config.m_SqlConnStr;
mCN.Open();
mCmd = new OleDbCommand();
mCmd.Connection = mCN;
}
catch (Exception ex)
{
U3Util.ErrorLog(ex.Message);
if (mCN != null) mCN.Close();
strMessage = "DB접속 오류: " + ex.Message;
return false;
}
int count = 0;
foreach (string strSql in strSqls)
{
strSQL = strSql;
try
{
mCmd.CommandText = strSql;
mCmd.ExecuteNonQuery();
count++;
}
catch (Exception ex)
{
U3Util.ErrorLog(strSQL);
U3Util.ErrorLog(ex.Message);
}
}
if (mCN != null) mCN.Close();
strMessage = string.Format("SQL 실행 완료({0}건 실행, {1}건 성공)", strSqls.Count, count);
return true;
}
}
}