Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2515
  • Last Modified:

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
0
Rajar Ahmed
Asked:
Rajar Ahmed
  • 8
  • 7
2 Solutions
 
slightwv (䄆 Netminder) Commented:
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.
0
 
Rajar AhmedConsultantAuthor Commented:
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 .
0
 
slightwv (䄆 Netminder) Commented:
>>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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Rajar AhmedConsultantAuthor Commented:
still error after adding reference,  i dint find any selection of processor on configurationmanager.
stillErrorAfterAddingReference.png
ijustfindthisnox86x64.png
0
 
slightwv (䄆 Netminder) Commented:
From your previous question:  Do you still have a reference in the web.config and did you manually add it?
0
 
Rajar AhmedConsultantAuthor Commented:
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
0
 
slightwv (䄆 Netminder) Commented:
>>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
0
 
Rajar AhmedConsultantAuthor Commented:
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

0
 
slightwv (䄆 Netminder) Commented:
>>This is my ora file .

That looks like a sample tnsnames.ora file.

Look under the OracleXE folder in NETWORK/ADMIN

>>Am still getting the same error ,

Looks like you have the cmd and conn string backwards.

http://docs.oracle.com/cd/B28359_01/win.111/b28375/OracleDataAdapterClass.htm

try:
Dim adapter As New OracleDataAdapter(sql, oradb)



You might have a password issue.  Starting in 11g database passwords are case-sensitive.  We'll cross that bridge if/when we get there.
0
 
Rajar AhmedConsultantAuthor Commented:
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
0
 
slightwv (䄆 Netminder) Commented:
>>ORA-12154: TNS:could not resolve the connect identifier specified

Which connect string were you using?  Your original or the one I posted in http:#a38322020

If should be the one I posted.
0
 
Rajar AhmedConsultantAuthor Commented:
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
0
 
slightwv (䄆 Netminder) Commented:
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.
0
 
Rajar AhmedConsultantAuthor Commented:
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
0
 
slightwv (䄆 Netminder) Commented:
>>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.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now