Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

odbc instructions to connect to oracle

I am trying to connect to an oracle database from my website (asp.net-mvc). The only information i have to connect to the database is ODBC instructions which tells me to go:

  1. It says to go into an oracle directory on the machine and enter this into a TSNNames.ora file and enter this in:

    DBNAME=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=[machine])(port=[port]))
       (CONNECT_DATA=(SID=[DBNAME])))
    
  2. and then go to control panel and manually add a connection through the GUI wizard.

Is there anyway i can connect to this database without have to set this up? I was hoping to simply stick a connection string in and be on my way. I deploy to different machines and i dont want the burden of having to update the .ora files or walk through this GUI wizard setup.

Does anyone have a suggestion for me?

like image 597
leora Avatar asked Nov 06 '10 19:11

leora


People also ask

Can we use ODBC to connect to Oracle database?

In the Oracle ODBC Driver Connect window the Service Name and User ID fields are prefilled with the information you supplied in the Oracle ODBC Driver Configuration window. Enter the password for your user ID and click OK. You are notified that the connection was created successfully. Click OK.

How do I test Microsoft ODBC for Oracle connection?

Start the ODBC test utility by selecting Start > Programs > Oracle > Network Administration > Oracle ODBC Test or by searching your system for the file ODBCTST. EXE and double clicking on the file. Click on the CONNECT button displayed by the ODBC Test utility.


1 Answers

Don't use ODBC. ODP.NET is a driver provided by Oracle which is based on the same model as SQL Server: simply download the assembly, reference it in your project and use it:

    using (var conn = new OracleConnection("Some connection string"))
    using (var cmd = conn.CreateCommand())
    {
       conn.Open();
       cmd.CommandText = "SELECT id FROM foo";
       using (var reader = cmd.ExecuteReader())
       {
          while (reader.Read())
          {
             int id = reader.GetInt32(0);
          }
       }
    }       
like image 62
Darin Dimitrov Avatar answered Sep 18 '22 12:09

Darin Dimitrov