Results 1 to 19 of 19

Thread: [RESOLVED] [2008] ODBC Oracle read

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Resolved [RESOLVED] [2008] ODBC Oracle read

    Hi
    Don't cut me into pieces for not beeing so clear in this subject. ODBC is new to me so I hope that I can get some help here. I'm trying to to connect to a Oracle database and read the content to a textbox. This is my code:

    Code:
    Dim conn As OdbcConnection
            Dim connectionString As String
            Try
                connectionString = "DSN=***;Driver={Microsoft ODBC for Oracle};Server=***.com;Uid=Bulk;Pwd=pwd;"
                conn = New OdbcConnection(connectionString)
                conn.Open()
                TextBox1.AppendText("Connection Open" & vbCrLf)
    
                Dim dbCommand As System.Data.OracleClient.OracleCommand
                Dim dbDataReader As System.Data.OracleClient.OracleDataReader
                dbDataReader = dbCommand.ExecuteReader()
    
                Do While dbDataReader.Read()
                    TextBox1.AppendText(dbDataReader(0).ToString & vbCrLf)
                Loop
    
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try
    Connection is ok, (I think) Connection Open shows in textbox, and no errors. But I get a nullexeption on the reader, it has not been assign a value. Don't know what to do next.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: [2008] ODBC Oracle read

    You never set the CommandText property for the dbCommand object, I think that's why it can't return a DataReader object when you do:
    Code:
    dbDataReader = dbCommand.ExecuteReader()
    Strange that it won't give an error on that line though.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: [2008] ODBC Oracle read

    Hi
    Well I get an error on that line. I still dont know how to read and display into textbox.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: [2008] ODBC Oracle read

    Ah, I see the problem now. You only declare dbCommand, you never instantiate it. Try this:

    Code:
    Dim dbCommand As New System.Data.OracleClient.OracleCommand("SELECT * FROM <YourTableName>", conn)
    That way you declare it, instantiate it and set the Connection and CommandText properties all at once.
    Last edited by Hamish; Jan 15th, 2009 at 06:53 AM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: [2008] ODBC Oracle read

    I get this:

    Error 1 Value of type 'System.Data.Odbc.OdbcConnection' cannot be converted to 'Oracle.DataAccess.Client.OracleConnection'.

  6. #6
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2008] ODBC Oracle read

    You need to be consistent in you peices. You declare and use ODBC connection and then try and use an Oracle.DataReader. You need to use the ODBC object completely if you want to go that way.

    But I know this is none of my business, but why are you using ODBC data connections the Oracle client stuff will perform better.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: [2008] ODBC Oracle read

    Hi
    I guess of no reason, but I have a ODBC client installed. I'm new to this and any connection could be used, I think.

  8. #8
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2008] ODBC Oracle read

    I would use the Oracle Client name space unless you are planing on making this DB independent. You will get better performance using the DB providers client.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: [2008] ODBC Oracle read

    Ok, thank's for the advice. Still trying to make it this way, for a while. This should work I guess, but I have problem with my table name.

    Code:
    Dim conn As OdbcConnection
            Dim connectionString As String
            Try
                connectionString = "DSN=***;Driver={Microsoft ODBC for Oracle};Server=***.com;Uid=Bulk;Pwd=pwd;"
                conn = New OdbcConnection(connectionString)
                conn.Open()
                TextBox1.AppendText("Connection Open" & vbCrLf)
    
                  Dim cmd As System.Data.Odbc.OdbcCommand
                Dim odbcomand As String
                Dim reader As System.Data.Odbc.OdbcDataReader = Nothing
    
                odbcomand = ("SELECT * FROM <My Table>")
                cmd = New OdbcCommand(odbcomand, conn)
                reader = cmd.ExecuteReader()
                Do While reader.Read()
                    TextBox1.AppendText(reader.Item(0) & "  -  " & reader.Item(1) & "  -  " & reader.Item(2) & vbCrLf)
                Loop
                reader.Close()
                cmd.Dispose()
                conn.Close()
            Catch ex As Exception
                MessageBox.Show(ex.ToString)
            End Try

  10. #10
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2008] ODBC Oracle read

    What is the problem..... What is the table name in Oracle?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: [2008] ODBC Oracle read

    The name of the table name I'm trying to display is found out from EXCEL.
    In EXCEL I import external data, new database query. From the query wizard I can see the tablenames in a textbox, for example TEST. This table name is what I'm trying to use.

  12. #12
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: [2008] ODBC Oracle read

    If the table is called TEST then you should use:

    Code:
                odbcomand = ("SELECT * FROM TEST")

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: [2008] ODBC Oracle read

    Tnank's. Should be close now, now I get that table or view does not exist.

  14. #14
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2008] ODBC Oracle read

    That seems pretty informative.... The table test does not exsist in the database to the user does not have permissions to view the table.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: [2008] ODBC Oracle read

    Ok, but I have access when import via EXCEL.

  16. #16
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [2008] ODBC Oracle read

    Do you the Oracle client on you machine? If so connect using the same username/password as in the connect string and attempt to select from the table using SQL*Plus or SQLDeveloper
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  17. #17
    Hyperactive Member
    Join Date
    Mar 2008
    Location
    Zeist, The Netherlands
    Posts
    266

    Re: [2008] ODBC Oracle read

    I don't know much about Oracle, but in SQL you can use Windows authentication or SQL autentication. Getting the data with Excel would be using Windows authentication (unless you specify another account in the process), while your connection string specifies a user account and password that make me suspect you're using some sort of integrated security here.
    Could that be the problem?

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: [2008] ODBC Oracle read

    When I import to EXCEL i connect with the same username/password as in the connection string, in the connection string I use Driver={Microsoft ODBC for Oracle};. In the query wizard I can see the tablenames, but theres a + sign infront of the name, I must click here to show the actual table. This table can then be imported to EXCEL.
    Last edited by BULK; Jan 16th, 2009 at 01:47 AM.

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: [2008] ODBC Oracle read

    Ok, I guess that I have to learn the commands I don't know much yet. What I can say is that this command will show all the metadata tables.
    Code:
    odbcomand = ("select * from dict")
    This is working, with my code.

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