string sql = "Provider=OraOLEDB.Oracle.1;Data Source=orcl;Persist Security Info=True;User ID=아이다;Password=비밀번호;"; //oracle 서버 연결 문자열
OleDbConnection conn = new OleDbConnection(sql);
conn.ConnectionString = sql;
try
{
conn.Open(); //데이터베이스 연결
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "select * from 테이블"; //테이블
cmd.CommandType = CommandType.Text; //검색쿼리
cmd.Connection = conn;
OleDbDataReader read = cmd.ExecuteReader(); //select 쿼리 결과
Console.WriteLine("***** 테이블 분석 결과 *****");
for (int i = 0; i < read.FieldCount; i++)
{
Console.WriteLine("필드이름 : {0} \n", read.GetName(i));
}
Console.WriteLine("총필드 개수는" + read.FieldCount);
read.Close();
}
catch (Exception ex)
{
Console.WriteLine("에러발생{0}", ex.Message);
}
finally
{
if (conn != null)
{
conn.Close(); //데이터베이스 연결 해제
Console.WriteLine("데이터베이스 연결 해제..");
}
}
Oracle
- [C#] OLEDB Oracle DB 연결하기 2011.05.26
[C#] OLEDB Oracle DB 연결하기
2011. 5. 26. 15:48