Press "Enter" to skip to content

Executing Oracle Command in VB.Net

Running Oracle commands in Vb.net with Tns less  connection string.

Imports required for the following procedure are:
Imports System.Data
Imports System.Data.OleDb

Pass the oracle command as parameter to following procedure.

Public Sub execute_oracledb_command(ByVal cmdstring As String)
        Dim oraconnection As OleDbConnection
        Dim oracommand As OleDbCommand

        dim srcconnect as string = “Provider=OraOLEDB.Oracle;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=YourHost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=YourService)));User Id=YourUser;Password=YourPsw;”

        oraconnection = New OleDbConnection(srcconnect)
        Try
            oraconnection.Open()
            ‘opening the connection
            oracommand = New OleDbCommand(cmdstring, oraconnection)
            oracommand.ExecuteNonQuery()
            oraconnection.Close()
        Catch ee As Exception
            messagebox.show(ee.message)
        End Try
End Sub

One Comment

  1. Khalid Qureshi Khalid Qureshi January 26, 2013

    This tns less connection string is good… works fine with .net 2005 to 2010…

Comments are closed.