VBA Connect Oracle DB

Sub ConnectDB()
  Dim strHost, strDatabase, strSQL, strUser
  Dim strPassword As String
  strHost = "localhost"
  strDatabase = "xe"
  strUser = "username"
  strPassword = "password"
  strSQL = "select * from bio01"
  
  Dim strConOracle, oConOracle, oRsOracle
  Dim StrResult As String
  StrResult = ""
  strConOracle = "Driver={Microsoft ODBC for Oracle}; " & _
         "CONNECTSTRING=(DESCRIPTION=" & _
         "(ADDRESS=(PROTOCOL=TCP)" & _
         "(HOST=" & strHost & ")(PORT=1521))" & _
         "(CONNECT_DATA=(SERVICE_NAME=" & strDatabase & "))); uid=" & strUser & " ;pwd=" & strPassword & ";"
  Set oConOracle = CreateObject("ADODB.Connection")
  Set oRsOracle = CreateObject("ADODB.Recordset")
  oConOracle.Open strConOracle
  Set oRsOracle = oConOracle.Execute(strSQL)
  
  MsgBox (oRsOracle.Fields(0).Value)
  

   
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: