Connect to ORACLE database using C#

Hi everyone…

you can connect to oracle database either by OleDb object or by DSN. Following code snippet did the trick. Go through it.

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);
}
}
}

Courtesy Ravi Shankar

Keep Smiling :)

About these ads

4 Responses to “Connect to ORACLE database using C#”

  1. ODBC Verbindung zu Oracle Datenbank aufbauen - .NET Datenverwaltung @ tutorials.de: Forum, Tutorial, Anleitung, Schulung & Hilfe Says:

    [...] passen. Kann es sein, dass du den DSN-Wert falsch eingetragen hast bzw. den falschen Wert nimmst? Hier kannst du dir auch noch ein Code-Snippet zu dem Thema ansehen. Vielleicht hilft dir das weiter. [...]

  2. wqwq Says:

    eeegtre’rtty’yyiyuo’

  3. vishal Says:

    hi wat are all the requirements i mean installations to connect to oracle database ?

  4. C# – Database Connection « Prayag Upd Says:

    [...] 4)Connect to ORACLE database using C# [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: