ODBC Connection to Oracle using ASP and ASPX

G

Guest

I have a problem trying to connect to an Oracle database using .NET but it works with ASP

System setting:
Windows 200
IIS with .NET Framework 1.
ODBC - Set up a DSN using Microsft ODBC Driver for Oracl
MDAC2.
Oracle9i Clien
An existing Oracle database running on another machine on the same local networ

ASP code that works
var dbPRM = Server.CreateObject("ADODB.Connection")
dbPRM.Open("DSN=" + DBDSN2 + ";UID=" + userID + ";PWD=" + passDB)

ASPX code that doesn't work

Code#
====
<%@ Page Language="C#" debug="true" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.Odbc" %><script language="C#" runat="server"
void Page_Load(Object src, EventArgs e)
try
string mySelectQuery = "SELECT * FROM TABLE"
string myConnString
"Driver={Microsoft ODBC for Oracle};DSN=XXX;UID=XXX;PWD=XXX;"

OdbcConnection myConnection = new OdbcConnection(myConnString)
OdbcCommand myCommand = new OdbcCommand(mySelectQuery,myConnection)
myConnection.Open()
OdbcDataReader myReader = myCommand.ExecuteReader()

while (myReader.Read())
Label1.Text = myReader.GetInt32(0) + ", " + myReader.GetString(1)
}
myReader.Close(); // always call Close when done reading.
myConnection.Close();// Close the connection when done with it

} catch (OdbcException ex)
Response.Write(ex.Message);
} finally {
}


Error message for Code#
================
ERROR [IM004] [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed

Pops up dialog: Oracle client and networking components were not found. These components are supplied by Oracle Corporation and are part of the Oracle Version 7.3.3 or later client software installation. Provider is unable to function until these components are installed.

Code #
=====
<%@ Page Language="C#" %><script runat="server"
void Page_Load(Object src, EventArgs e)
try
string myselectQuery = "SELECT * from TABLE"
string myConnString = "Provider=MSDAORA;User Id=XXX;Password=XXX;Data Source=[name in tnsnames.ora];OLEDB.NET=true;";
System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(myConnString)
System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand()
dbCommand.CommandText = myselectQuery
dbCommand.Connection = dbConnection

dbConnection.Open()
System.Data.IDataReader myReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

while (myReader.Read())
Label1.Text = myReader.GetString(0) + " Connection to database successfully established!";

myReader.Close(); // always call Close when done reading
dbConnection.Close(); // Close the connection when done with it

} catch (System.Exception ex) {
Response.Write(ex.Message)
} finally



Error message for Code #
=================
Oracle client and networking components were not found. These components are supplied by Oracle Corporation and are part of the Oracle Version 7.3.3 or later client software installation. Provider is unable to function until these components are installed.

Note: I created a simple MS Access db on my local machine and changed the myConnString t
string myConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=XXX.mdb"
and it works

One last question
Can someone please explain the difference between ODBCConnection (System.Data.ODBC) vs OracleConnection (System.Data.OracleClient) vs OLE DB?

Also, I am having trouble in import the namespaces System.Data.OracleClient, but I can import the namespace for System.Data.ODBC... Why is this happening

I am running out of ideas of what I could do to get it to work! Any help is greatly appreciated!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top