Results 1 to 6 of 6

Thread: How To Connect Oracle Using Odbc

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    2

    Question How To Connect Oracle Using Odbc

    Hai all.

    I request your valuable help.

    I have VB 6.0 and Oracle 8 personnel edition in my system. I would like access oracle database using ODBC. I tried by creating a user DSN through Windows Cotrol Panel. Then while accessing through VB it asks SQL Server login. SQL server is not there. There it terminates. Can someone tell me the exact procedure starting from the very begining, for connecting the Oracle database through ODBC and how to access the data.

    Thanking You.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    You also need to setup the connection using the Net8 assistant.

    Basically all the ODBC Connection is, is a passthrough to the Net8 setup.

    Once you do that you can use ADO to connect to the database using the ADO.Connection object. To get data from the database you can use the ADO.Recordset object.

    Here is a link to a good site on connection strings:
    http://www.able-consulting.com/ADO_Conn.htm

    Hope this helps,

  3. #3
    Addicted Member
    Join Date
    Sep 2001
    Location
    Florida
    Posts
    213
    VB Code:
    1. Option Explicit
    2.  
    3. Const DB_NAME = "yourdatasource"
    4. Const DB_UID = "youruserID"
    5. Const DB_PWD = "yourpassword"
    6.  
    7. Dim conAVB As ADODB.Connection
    8. Dim yourTable As ADODB.Recordset
    9. -----------------
    10.  
    11. 'Create the connection
    12.     Dim strSQL  As String
    13.     Set conAVB = New ADODB.Connection
    14.    
    15.     On Error GoTo HandleErrors
    16.     conAVB.ConnectionString = "Provider=MSDAORA;" & _
    17.             "Password=" & DB_PWD & _
    18.             ";User ID=" & DB_UID & _
    19.             ";Data Source=" & DB_NAME & _
    20.             ";Persist Security Info=True"
    21.     conAVB.Open
    22.  
    23.     Set YourTable= New ADODB.Recordset
    24.     strSQL = "Select * from yourTable"
    25.     Set YourTable = conAVB.Execute(strSQL, , adCmdText)
    Last edited by vbvbvbvb; Jan 9th, 2002 at 09:19 AM.

  4. #4
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    it must be made clear that vbvbvb's suggestion is not an ODBC connection - MSDAORA is an OLEDB provider.

    ..which is the better way of connecting to an Oracle database over ODBC as it has one less layer, and doesn't require you to set up a system DSN.

    FYI, there is another way to access Oracle data, that has even less layers than OLEDB - Oracle own OO4O. I never use it though....

  5. #5
    Addicted Member
    Join Date
    Sep 2001
    Location
    Florida
    Posts
    213
    Gaffer, is this the way you are talking about?

    VB Code:
    1. Private Session As Object 'OracleInProcServer.OraSession
    2. Private Database As Object 'OracleInProcServer.OraDatabase
    3. Private dbTable As Object 'OracleInProcServer.OraDynaset
    4. Private Const ORADB_NOWAIT = &H2&
    5. Private Const ORADYN_DEFAULT = &H0&
    6.  
    7. Const UserName = " ?"
    8. Const Password = "?"
    9. Const DatabaseName = "?"
    10. -------------------
    11.  
    12.     Dim a$
    13.     Dim strSQL As String
    14.  
    15.     Set Database = Nothing
    16.     a$ = UserName & "/" & Password
    17.     Set Session = CreateObject("OracleInProcServer.XOraSession")
    18.     Set Database = Session.OpenDatabase(DatabaseName, a$, ORADB_NOWAIT)
    19.    
    20.     Set dbTable = Nothing
    21.     strSQL = "SELECT * from yourtable"
    22.     Set dbTable = Database.CreateDynaset(strSQL, ORADYN_DEFAULT)

  6. #6
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    That's the boy. As I said, I never used OO4O in a completed project as it's benefits seem negible. It's benefits are:

    a) Direct Access to Oracle Call Interface (whereas ADO uses OLE DB as an extra layer). Probably not going to make much of a performance difference
    b) It's built for Oracle Stored Procedures. But I always found that ADO give me everythign I need
    c) It's built for Oracle - say what you want about ADO being multi databse compatible - it was really built for SQL Server. However, again, you can usually do your work competantly enough using ADO & Oracle

    However, ADO & OLEDB is used by almost everyone now, is asynchronous (OO4O isn't), and OLEDB is much quicker than ODBC....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width