본문 바로가기

DEV/VB

VisualBasic ODBC를 이용한 DB접속

반응형
기본적으로 project-references-MicroSoft ActiveX Data Objects 2.8 Library가 체크인
되어 있어야한다.

- MsSql 접속


  '선언부

  Dim RS_MS As ADODB.Recordset
  Dim ado_MS As ADODB.Connection

  '사용시
  Dim strconn As String

  strconn = "Provider=MSDASQL;dsn=dsnname;Database=databasename;UID=username;PWD=password;"

  Set ado_MS = New ADODB.Connection
  ado_MS.CursorLocation = adUseClient
  ado_MS.Open strconn


- Oracle 접속

  '선언부
  Dim ado_Ora As ADODB.Connection
  Dim RS_Ora As ADODB.Recordset

  '사용시
  Dim strconn As String

  strconn = "Provider=MSDAORA.1;Persist Security Info=False;User ID=userid;Password=password;Data Source=datasourcename"

  Set ado_Ora = New ADODB.Connection
  ado_Ora.CursorLocation = adUseClient
  ado_Ora.Open strconn


- MySql 접속

  '선언부

  Dim RS_MS As ADODB.Recordset
  Dim ado_MS As ADODB.Connection

  '사용시
  Dim strconn As String

  strconn = "DRIVER={MySQL ODBC 3.51 Driver};server=servername;uid=userid;pwd=password;database=dbname;option=3;port=3306;STMT=SET NAMES EUCKR"

  Set ado_MS = New ADODB.Connection
  ado_MS.CursorLocation = adUseClient
  ado_MS.Open strconn
반응형
댓글