8

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?

leora
  • 188,729
  • 360
  • 878
  • 1,366

3 Answers3

10

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);
          }
       }
    }       
MikroDel
  • 6,705
  • 7
  • 39
  • 74
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • See [this stackoverflow](http://stackoverflow.com/questions/659341/the-provider-is-not-compatible-with-the-version-of-oracle-client) for details on the minimal set of libraries required for distribution. – Nigel Touch Nov 29 '12 at 14:31
2

According to a similar question, Manually connecting to database in Asp.net MVC, there's no magic involved. Just connect to the db as you normally would.

There's a VB example @ http://www.aspdev.org/articles/asp.net-mysql-connect/ It's for MySql but should be simple enough to switch to your Oracle connection string.

Community
  • 1
  • 1
Farray
  • 8,290
  • 3
  • 33
  • 37
0

There is at least one ado.net provider for Oracle that doesn't require an Oracle client on the machine. See http://www.devart.com/dotconnect/oracle/. Devart calls this feature 'direct mode'. This Oracle specific provider will also probably perform much better than an odbc provider.

But there is something I don't understand? You have build an asp.net mvc application so you only have to install on a server. So what is the problem?

TTT
  • 2,365
  • 17
  • 16