Connect to Oracle?

cboshdave

New member
Joined
Feb 7, 2013
Messages
1
Programming Experience
1-3
I am trying to connect to Oracle. I know I am close but missing something. I have attached my code. I am wondering if I am missing and Imports statement?

VB.NET:
Imports System.Data.OleDb
Imports System.Data.SqlClient


Private Sub btnOracleDBConnect_Click(sender As Object, e As EventArgs) Handles btnOracleDBConnect.Click        Dim oledbCommand As OleDbCommand
        Dim dr As OleDbDataReader


        Dim sOracledb As New OleDb.OleDbConnection("PROVIDER=MSDAORA;UserID=user;password=pw;database=db")
        'Doesn't work -->"PROVIDER=OraOLEDB.Oracle;UserID=user;password=pw;database=db"
        'Doesn't work -->"PROVIDER=MSDAORA;UserID=user;password=pw;database=db"
        'Doesn't work -->"PROVIDER=MSDAORA.1;UserID=user;password=pw;database=db"


        Dim sSQL As String = "select * from MCO_PROVIDER_COUNTY;"  'Test query to see if it is working.
        oledbCommand = New OleDbCommand(sSQL, sOracledb)


        Try
            sOracledb.Open()
            'DataReader can be done in Memory.
            dr = oledbCommand.ExecuteReader()
            While dr.Read()
                'reading from the datareader
                MessageBox.Show("County ID: " & dr(0))
                MessageBox.Show("County Name: " & dr(1))
                'MessageBox.Show("Job" & dr(2))
                'MessageBox.Show("Mgr" & dr(3))
                'MessageBox.Show("HireDate" & dr(4))
                'displaying data from the table
            End While
            dr.Close()
            sOracledb.Close()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)


        End Try
    End Sub
 
Firstly, whenever you have an issue, please explain it fully. You have showed us some code and told us that it doesn't work but you haven't told us how exactly you know that it doesn't work. Presumably something happens that you don't expect, either at compile time or run time. What? If there's a error then show us what line it occurs on and tell us what the error message is. That way we can hone straight in on the problem rather than wasting our time working out where it might be first.

From what I can see, you are having issues with your connection string. Regardless of the data source, whenever you need a connection string, your first step should be to visit www.connectionstrings.com. If you do that then it should be immediately obvious that none of your attempts are the same as theirs.

Also, if you're going to try to use OleDb to connect to Oracle then you have to make sure that you have the specified OLE DB provider installed. I don't know for a fact but I'm guessing that MSDAORA is installed by default on Windows but if you want to use a provider from Oracle then that would need to be installed separately.

Finally, I recommend not using OleDb anyway. I'd suggest that you download and install ODP.NET from Oracle. When you add the reference to your project, make sure that you set Copy Local to True and then that DLL will be output with your EXE and you just deploy them both.
 
Back
Top