Pantamtuy
Pantamtuy

Reputation: 243

oracle10g vb.net connection error

Imports System.Data.OleDb
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim conn As New Odbc.OdbcConnection
        Dim cmd As New Odbc.OdbcCommand
        Dim drResult As Odbc.OdbcDataReader
        Dim connString As String
        Dim QuerySQL As String

        connString = "(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = host)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = servicename)));Uid=user;Pwd=pwd;"
        QuerySQL = "select * from table"

        conn.ConnectionString = connString
        conn.Open()
        cmd.Connection = conn
        cmd.CommandText = QuerySQL
        drResult = cmd.ExecuteReader()

        While drResult.Read
            TextBox1.Text = TextBox1.Text & drResult("firstname") & ", " & drResult("lastname") & Environment.NewLine
        End While
        drResult.Close()
    End Sub
End Class

i am trying to connect to oracle using this code but an error occurred saying:

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

i am 100% sure about the tsname bcoz i've already used it in my php code. pls help me guys im just a newbie in vb.net. so what did i do wrong? can u pls guys help me...tnx

update tried this code but still theres an error:

 Dim myConnection As OleDbConnection
    Dim myCommand As OleDbCommand
  Dim myConnection As New OracleConnection(connStr)
            myConnection.Open()

Upvotes: 0

Views: 248

Answers (1)

Wernfried Domscheit
Wernfried Domscheit

Reputation: 59642

The connection string is wrong.

For OLE DB the connection string looks like this:

Provider=OraOLEDB.Oracle;Data Source=db_name;User Id=user;Password=pwd

db_name usally is an entry from your tnsnames.ora file. However, you can copy it directly, e. g.

Provider=OraOLEDB.Oracle;Data Source="(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = host)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = servicename)))";User Id=user;Password=pwd

For ODBC the connection string looks like this:

Driver="Oracle in OraClient11g_home1";Uid=user;Pwd=pwd;DBQ=db_name

Other connecting strings you find here:

Upvotes: 1

Related Questions