'2012/08'에 해당되는 글 3건

  1. 2012.08.29 C#으로 오라클접속 by 초코송송이
  2. 2012.08.28 C#으로 MySql 접속 by 초코송송이
  3. 2012.08.28 C#으로 Active Directory 접근 by 초코송송이

1.Oracle Data Access Components for Windows를 다운로드한다.

http://www.oracle.com/technetwork/indexes/downloads/index.html?ssSourceSiteId=ocomen

=>설치할 때, 필수항목으로 Instant Client가 설치되는데 이미 설치되어 있어도 다시 하도록 되어있었음..;;

2. using Oracle.DataAccess.Client;

string oradb = "Data Source=(DESCRIPTION="              
              + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.xxx)(PORT=1521)))"
                //+ "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl.xxxx.com)));"
                + "(CONNECT_DATA=(SERVER=DEDICATED)(SID=ORCL)));"
                + "User Id=user;Password=password;";//service_name은 전역데이터베이스이름
                       
using (OracleConnection conn = new OracleConnection(oradb))
{
    try
    {
        conn.Open();

        using (OracleCommand cmd = new OracleCommand())
        {
            cmd.Connection = conn;
            cmd.CommandText = "select * from " +  tablename;

            OracleDataReader dr = cmd.ExecuteReader();                                                             

            while(dr.Read())
            { 
                 MessageBox.Show(dr.GetString(1));

....

      }

      cmd.CommandText = "insert into " + tablename + " (column1, column2, column3)"
                                                       + " VALUES('" + val1 + "', '" + val3 + "', '" + val3 + "')";

      int Res = cmd.ExecuteNonQuery();
      if (Res == 1)
      {
          System.Diagnostics.Trace.WriteLine("insert 성공");
      }
      else
      {
          System.Diagnostics.Trace.WriteLine("insert 실패");
      }

        }

    }
    catch (OracleException ex) // catches only Oracle errors
    {
        switch (ex.Number)
        {
            case 1:
                MessageBox.Show("Error attempting to insert duplicate data.");
                break;

            case 12545:
                MessageBox.Show("The database is unavailable.");
                break;

            default:
                MessageBox.Show("Database error: " + ex.Message.ToString());
                break;
        }
    }

    catch (Exception ex) // catches any other error
    {
        MessageBox.Show(ex.Message.ToString());
    }
    finally
    {
         // Don't need conn.Close() because the using takes care of it.
    }
}

'프로그래밍 > C#' 카테고리의 다른 글

C#으로 MySql 접속  (0) 2012.08.28
C#으로 Active Directory 접근  (0) 2012.08.28
C#의 객체지향  (0) 2012.05.10
C#의 기본문법  (0) 2012.05.08
Posted by 초코송송이
l

1. mysql-connector-net 설치

http://www.mysql.com/downloads/connector/net/

2. Reference에 추가 - MySql.Data

3. 소스에 적용

using MySql.Data;
using MySql.Data.MySqlClient;

static string DBConnectString = "Data Source=192.168.0.xxx;Database=db_name;" + "User Id=userid;Password=password" + ";charset=utf8";

MySqlConnection Con = new MySqlConnection();
Con.ConnectionString = DBConnectString;
            
try
{
    Con.Open();
         
    MySqlCommand Command = new MySqlCommand("SELECT * FROM table_name", Con);
    MySqlDataReader DataReader;
    DataReader = Command.ExecuteReader();

    while (DataReader.Read())
    {
         MappingTable MappingT = new MappingTable();
         MappingT.MappingNumber = string.Format("{0}", DataReader["table_column1"]);
         MappingT.UserId = string.Format("{0}", DataReader["table_column2"]);
         MappingT.SIP = string.Format("{0}", DataReader["table_column3"]);
         MappingTList.Add(MappingT);
    }
    DataReader.Close();
    Con.Close();
}

catch (MySqlException ex)
{
    MessageBox.Show(ex.ToString());
}

'프로그래밍 > C#' 카테고리의 다른 글

C#으로 오라클접속  (0) 2012.08.29
C#으로 Active Directory 접근  (0) 2012.08.28
C#의 객체지향  (0) 2012.05.10
C#의 기본문법  (0) 2012.05.08
Posted by 초코송송이
l

1. Active Directory에 조직구성단위 추가

using System.DirectoryServices;

DirectorySearcher DSESearcher = new DirectorySearcher();
DirectoryEntries DEntries = DSESearcher.SearchRoot.Children;                
DirectoryEntry ou2 = DEntries.Add("OU=" + OrgName, "organizationalUnit");
ou2.CommitChanges();
ou2.Close();

2. 조직구성단위 열거

DirectorySearcher DSESearcher = new DirectorySearcher();
DirectoryEntries DEntries = DSESearcher.SearchRoot.Children;
List<string> listOU = new List<string>();

foreach (DirectoryEntry de in DEntries)
{
    if (de.Name.CompareTo("OU") > 0)
    {
        listOU.Add(de.Name.Remove(0, 3));//OU=구성단위이름

     }                
}    

3. 조직구성단위에서 사용자 추가

DirectorySearcher DSESearcher = new DirectorySearcher();
string RootDSE;
try
{
    RootDSE = DSESearcher.SearchRoot.Path;
}
catch
{
    System.Windows.MessageBox.Show("Active Directroy를 찾을수 없습니다.");
    return;
}

//조직구성단위 목록을 미리 가지고 와서 콤보박스에서 선택             
RootDSE = RootDSE.Insert(7, "OU="+ comboBoxOU.SelectedValue +",");
DirectoryEntry myDE = new DirectoryEntry(RootDSE);

//선택한 조직구성단위 아래에 사용자 추가

DirectoryEntry usr = myDE.Children.Add("CN=" + textBoxFName.Text + " " + textBoxGName.Text, "user");
 
//계정 - Windows 2000 이전버전 사용자 로그온 이름
usr.Properties["samAccountName"].Value = textBoxLogonName.Text;
//일반 - 표시이름
usr.Properties["displayName"].Value = textBoxFName.Text + " " + textBoxGName.Text;
//일반 - 이름
usr.Properties["givenname"].Value = textBoxGName.Text;
//일반 - 성
usr.Properties["sn"].Value = textBoxFName.Text; //family name
//계정 - 사용자 로그온 이름
usr.Properties["userPrincipalName"].Value = textBoxLogonName.Text + "@xxxxxx.com";
//조직 - 회사
if (textBoxCompany.Text.Length > 0)
    usr.Properties["company"].Value = textBoxCompany.Text;
//일반 - 전화 번호
if (textBoxTelNum.Text.Length > 0)
    usr.Properties["telephoneNumber"].Value = textBoxTelNum.Text;
//조직 - 직함
if (textBoxTitle.Text.Length > 0)
    usr.Properties["title"].Value = textBoxTitle.Text;
//조직 - 부서
if (textBoxDepartment.Text.Length > 0)
    usr.Properties["department"].Value = textBoxDepartment.Text;
//일반 - 전자 메일
if (textBoxMail.Text.Length > 0)
    usr.Properties["mail"].Value = textBoxMail.Text;

usr.CommitChanges();

usr.Invoke("SetPassword", textBoxPassword.Text);
//usr.Invoke("SetPassword", new object[] { textBoxPW.Text });

int val = (int)usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val & ~0x2; //ADS_UF_NORMAL_ACCOUNT;
usr.CommitChanges();

myDE.Close();
usr.Close();

//(조직구성단위:OU, 사용자:CN)

'프로그래밍 > C#' 카테고리의 다른 글

C#으로 오라클접속  (0) 2012.08.29
C#으로 MySql 접속  (0) 2012.08.28
C#의 객체지향  (0) 2012.05.10
C#의 기본문법  (0) 2012.05.08
Posted by 초코송송이
l