Link to home
Start Free TrialLog in
Avatar of Rajar Ahmed
Rajar AhmedFlag for India

asked on

Connect oracle database in asp.net

Trying to import oracle objects and make some crud operation to work in  asp.net application as we do it in sql database using system.data.sqlclient . But i get these errors which i attached on the image.

Imports Oracle.DataAccess

Partial Class firstOracle
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As New OracleConnection

    End Sub
End Class

Open in new window


I installed the ODAC112030_x64.zip version on my pc ,
http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html


Using oracle 11g,sql oracle developer
oracleErrorWhileInvokingAsp.net.png
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Take out:
Imports Oracle.DataAccess


Add:
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types


Also make sure your VS project is set up to be 64bit since you installed the 64bit ODAC.
Avatar of Rajar Ahmed

ASKER

i get these warnings still
Warning	4	Namespace or type specified in the Imports 'Oracle.DataAccess.Types' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

Warning	4	Namespace or type specified in the Imports 'Oracle.DataAccess.client' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

Open in new window


Also make sure your VS project is set up to be 64bit since you installed the 64bit ODAC?
How to check this ?

I use both express edition of vs2010,vs2012 frequently . now this error on vs2010 .
>>i get these warnings still

Did you add a reference in the project to Oracle.DataAccess.dll?

>>How to check this ?

Check this out:
http://www.brianpeek.com/post/2007/11/13/x64-development-with-net.aspx
still error after adding reference,  i dint find any selection of processor on configurationmanager.
stillErrorAfterAddingReference.png
ijustfindthisnox86x64.png
From your previous question:  Do you still have a reference in the web.config and did you manually add it?
hi slightwv,

yes , now am getting object from orace.dataaccess.client.
but am getting this error,

Connection string is not well-formed ,

Open in new window

myfirstuser is the database which we created freshly on last post

Imports Oracle.DataAccess.Client
Imports System.Data

Partial Class firstOracle
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Dim oradb As String = "User Id=myfirstuser;Password=myPassword;Data Source=localhost" 'Trying to connect using this oracle connection 
        Dim sql As String = "select sysdate from dual;"
        Dim adapter As New OracleDataAdapter(oradb, sql)
        Dim builder As New OracleCommandBuilder(adapter)

        Dim dataset As New DataSet()

        adapter.Fill(dataset, "t_mobile")

        Dim mytable As DataTable = dataset.Tables("t_mobile")


    End Sub
End Class

Open in new window


What am i  missing ?

Meeran03
>>Data Source=localhost

Data Source in ODP.Net is the entry in the tnsnames.ora file.

try this:
        Dim oradb As String = "User Id=myfirstuser;Password=myPassword;Data Source=XE" 'Trying to connect using this oracle connection
Am still getting the same error , while trying with your connection string also.
This is my ora file .
<data source alias> =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = <hostname or IP>)(PORT = <port>))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = <database service name>)
    )
  )

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is where it located .
C:\oraclexe\app\oracle\product\11.2.0\server\network\ADMIN\
And the file content is below.
XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = hostname-pc)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  );

EXTPROC_CONNECTION_DATA =
  .................

ORACLR_CONNECTION_DATA = 
 ----------

Open in new window


Am getting this , after interchanging to sql,oradb
ORA-12154: TNS:could not resolve the connect identifier specified
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yaaaa got it.....This connection works.

Dim oradb As String = "User Id=myfirstuser;Password=myPassword;Data Source=localhost;"

Open in new window


Thank you for the support.

Meeran03
I'm not sure why just "localhost" works.  I've never seen a connection string for .Net work this way.

It may not work for you moving forward.
hi slightwv,
 I've never seen a connection string for .Net
  while using sql server we used to connect such a way only in local source , i tried the same for oracle . luckily it was working .

It may not work for you moving forward
 Well, yes , thats a valid point . I may ask a seperate thread if am stuck .

What i thought initially?
 To connect oracle from .net we just need a oracle database and oracle.dataaccess.dll but i was totally wrong its odac was doing the underground work.I hope am right on this:).

Thanks&Regards
Meeran03
>>while using sql server we used to connect such a way only in local source , i tried the same for oracle .

You really can't compare SQL Server to Orcle this way.  If you were to create a new database intance, it is stand alone.  It doesn't run in a Server like SQL Server.  Using localhost will likely get confused.

Oracle mainly either uses EZConnect or references the tnenames,ora file.

using localhost the way you did is likely thinking EZCONNECT and can find the XE instance.

>>but i was totally wrong its odac was doing the underground work.I hope am right on this:).

You need a properly configured Oracle Client.  Some use a third party like DotNetConnect which doesn't require an Oracle client.  Most use an Oracle client.