SIGN UP MEMBER LOGIN:    
ARTICLE
Reader Level:

Description of the Article

A Simple program to show connecting to an oracle database.

Source Code:

/********************************/
//Program Name : ADO Connection to Oracle
//Description : A Sample program to connect to the oracle database
//Created On : 01 May 2001
//Created By : Ravi Shankar Venkatarajalu
/********************************/
using System;
using System.Data;
using System.Data.ADO;
class OracleTest
{
static void Main()
{
//UID - User Id
//PWD - Password
//Server - Your Service name
//Using Microsoft ODBC for Oracle DSN-Less
//const string strConn = "Provider=MSDASQL;DRIVER={Microsoft ODBC for ORACLE};UID=scott;PWD=tiger;Server=fnqa";
//Using Microsoft OLEDB Provider for Oracle
const string strConn = "Provider=MSDAORA.1;
Data Source=oracle_db;User ID=scott;Password=tiger";
//Using DSN Connection
//const string strConn ="DSN=oracle_dsn;UID=scott;PWD=tiger" ;
const string strSQL = "Select * From EMP";
try
{
DataSet ds = new DataSet("EmployeesSet");
ADODataSetCommand myCommand = new ADODataSetCommand(strSQL,strConn);
myCommand.FillDataSet(ds,"Buyer");
Console.WriteLine(ds.Xml);
}
catch(ADOException e)
{
Console.WriteLine("Exception Occured :{0}",e.Errors[0].Message);
}
}
}

Login to add your contents and source code to this article
share this article :
post comment
 

using System.Data.ADO; this line in the above code is giving below error for me.Error 1 The type or namespace name 'ADO' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) C:\Documents and Settings\abhilash\My Documents\Visual Studio 2008\Projects\DBConnect\DBConnect\Program.cs 3 19 DBConnect

Posted by Abhi MFC May 16, 2012

I m unable to connect oracle database with C#.net. "MSDORA provider is not install in your local machine". i hv to install oracle client version on my local machine? Or i can directly connect. Provider name, Connection string format?

Posted by harish dhoundiyal Mar 31, 2011

this works with ORACLE EXPRESS 10g? also data source would mean the name of the database,is this correct?

Posted by pes Mar 01, 2010

i want to conect to remote  oracle database from my c# application using Oracleclient , not ADO. how can i do that. i have tried using folowing connection string
data source='@192.168.0.37/xe; uid=uid;password=pass;
but experience the following error;
ORA-12154: TNS:could not resolve service name
plz help me.

Posted by bandhan Feb 03, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Team Foundation Server Hosting
Become a Sponsor