简体   繁体   English

使用C#连接到Oracle DB

[英]Connecting to Oracle DB using C#

I want to connect Oracle Database in .net platform using C# 我想使用C#在.net平台中连接Oracle数据库

and here is some code 这是一些代码

  _connectionString = "Provider=MSDAORA.1;Data Source=yong;User ID=XXXX;Password=XXXX";

  using (OdbcConnection sqlConnection = new OdbcConnection(_connectionString))
            {
                using (OdbcDataAdapter adapter = new OdbcDataAdapter())
                {
                    try {
                        adapter.SelectCommand = new OdbcCommand(cmdText, sqlConnection);
                        adapter.SelectCommand.CommandType = commandType;
                        adapter.SelectCommand.CommandTimeout = _commandTimeOut;
                        adapter.SelectCommand.Connection.Open();
                        adapter.Fill(dtResult);
                        }
                catch (Exception ex)
                {
                    throw ex;
                }
               }
            }

when I try this code, it throws error like 当我尝试这段代码时,它会抛出错误

" msdaora.1' provider is not registered on the local machine " “ msdaora.1'提供程序未在本地计算机上注册”

I don't get what is a problem and how to fix this. 我没有任何问题以及如何解决此问题。 How do I register a msdaora.1 provider on the local machine and what's wrong with my code? 如何在本地计算机上注册msdaora.1提供程序,我的代码有什么问题?

Try downloading and installing the Oracle Data Access Components. 尝试下载并安装Oracle Data Access Components。 Here are links to the 32 bit and 64 bit versions. 这里是32位64位版本的链接。 Also, just from personal experience, I would use the oracle OleDb adapter instead of that one, but that's because I've had trouble connecting to RAC clusters with other adapters. 另外,仅凭个人经验,我将使用oracle OleDb适配器而不是那个,但这是因为我在使用其他适配器连接到RAC群集时遇到了麻烦。

Edit: You're also going to run into problems when you deploy the app to an environment that doesn't have ODAC installed, so here some further suggested reading . 编辑:将应用程序部署到未安装ODAC的环境时,您还将遇到问题,因此,这里有一些建议阅读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM