oracle 连接oracle的odbc指令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4114824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:52:14  来源:igfitidea点击:

odbc instructions to connect to oracle

c#asp.net-mvcoracleodbc

提问by leora

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:

我正在尝试从我的网站 (asp.net-mvc) 连接到 oracle 数据库。我必须连接到数据库的唯一信息是 ODBC 指令,它告诉我去:

  1. It says to go into an oracle directory on the machine and enter this into a TSNNames.orafile 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.

  1. 它说进入机器上的 oracle 目录并将其输入到TSNNames.ora文件中,然后输入:

    DBNAME=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=[machine])(port=[port]))
       (CONNECT_DATA=(SID=[DBNAME])))
    
  2. 然后转到控制面板并通过 GUI 向导手动添加连接。

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.

无论如何我可以连接到这个数据库而不必设置它?我希望简单地插入一个连接字符串并在路上。我部署到不同的机器上,我不想承担更新 .ora 文件或完成此 GUI 向导设置的负担。

Does anyone have a suggestion for me?

有人对我有什么建议吗?

回答by Darin Dimitrov

Don't use ODBC. ODP.NETis 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:

不要使用 ODBC。ODP.NET是 Oracle 提供的驱动程序,它基于与 SQL Server 相同的模型:只需下载程序集,在您的项目中引用它并使用它:

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

回答by Farray

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.

根据一个类似的问题,在 Asp.net MVC 中手动连接到数据库,不涉及魔法。只需像往常一样连接到数据库。

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.

有一个 VB 示例 @ http://www.aspdev.org/articles/asp.net-mysql-connect/它用于 MySql 但应该足够简单以切换到您的 Oracle 连接字符串。

回答by TTT

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.

至少有一个用于 Oracle 的 ado.net 提供程序不需要机器上的 Oracle 客户端。请参阅http://www.devart.com/dotconnect/oracle/。Devart 将此功能称为“直接模式”。此 Oracle 特定提供程序的性能也可能比 odbc 提供程序好得多。

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?

但有什么我不明白的吗?您已经构建了一个 asp.net mvc 应用程序,因此您只需安装在服务器上。那么问题出在哪里呢?