-1

I'm a beginner to using vb.net, on this issue I want to connect Oracle 12c to my visual basic application. I think everything is correct, and the application can also be run. but when i want to test the connection, my console displays an error Exception thrown: 'System.IO.FileNotFoundException' in Hotel.dll

Here is my code :

Imports Oracle.DataAccess.Client
Public Class Form1
    Dim con As New OracleConnection
    Dim cmd As New OracleCommand
    Dim sql As String

    Private Sub btntest_Click(sender As Object, e As EventArgs) Handles btntest.Click
        dbAccess()
    End Sub

    Private Sub dbAccess()
        con = New OracleConnection
        Try
            con.ConnectionString = "Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pdborcl))); user id=admin;password=admin"
            con.Open()
            MsgBox("Connection OK")
        Catch ex As Exception
            MsgBox("Connection Fail")
        End Try
    End Sub
End Class

Here is the error :

https://i.ibb.co/443qTQ0/Untitled.png https://i.ibb.co/84D8Rty/Untitledx.png

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Please don't use the VBA tag for VB.NET – Tim Williams Dec 05 '21 at 18:10
  • The following may be helpful: https://stackoverflow.com/questions/68591698/program-not-responding-when-executing-oracledataadapter-fill/68595986#68595986 and https://docs.oracle.com/en/database/oracle/oracle-database/12.2/odpnt/intro005.html – Tu deschizi eu inchid Dec 05 '21 at 20:01

1 Answers1

0

Connection and commands need to be declared locally in Using blocks in the method where they are used. They contain unmanaged resources which the class releases in a Dispose method. Using blocks close and dispose these objects even if there is an error.

Calling ToString on the Exception should give you more details on the problem.

For connection problems see https://www.connectionstrings.com/oracle-data-provider-for-net-odp-net/

Private OracleConstring As String = "Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = pdborcl))); user id=admin;password=admin"

Private Sub dbAccess()
    Using con As New OracleConnection(OracleConstring)
        Try
            con.Open()
            MsgBox("Connection OK")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Using
End Sub
Mary
  • 14,926
  • 3
  • 18
  • 27