在 C# .Net 中连接到 oracle 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1400207/
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 18:58:33  来源:igfitidea点击:

Connecting to an oracle database in C# .Net

c#.netoracle

提问by lisburnite

Hi I use the following code to connect to an orace database in Visual Studio 2008 and it is falling over with the exception of ServerVersion threw an invalid operation exception at line 3:

嗨,我使用以下代码连接到 Visual Studio 2008 中的 orace 数据库,它正在失败,但 ServerVersion 在第 3 行抛出了无效操作异常:

m_strConnectionString = Settings.GetMandatoryConfig("databases", "SourceDB");
m_strQueryTerminator = Settings.GetConfig("databases", "QueryTerminator");
m_odbConn = new OleDbConnection(m_strConnectionString);
m_sql = new SQL(DatabaseType.AnsiSQL, false);

m_strConnectionString is a valid TNS names connection string and is as follows:

m_strConnectionString 是有效的 TNS 名称连接字符串,如下所示:

Provider=MSDAORA;Data Source=myDS;User ID=myID;Password=myPW

提供者=MSDAORA;数据源=myDS;用户ID=myID;密码=myPW

This has previously worked and is using an IIS web server to host the application. I recently converted it from .Net 1.1 (VS 2003) to .Net 3.5/2 (VS 2008) and can't get it working as yet in VS 2008.

这以前是有效的,并且正在使用 IIS Web 服务器来托管应用程序。我最近将它从 .Net 1.1 (VS 2003) 转换为 .Net 3.5/2 (VS 2008),但在 VS 2008 中还不能让它工作。

Thanks

谢谢

采纳答案by Scott Ivey

Maybe you should consider using the OracleConnectionclass instead of the generic OleDbConnection. Doing this may give you more specific error information that what you're receiving now - and could help you find your problem quicker.

也许您应该考虑使用OracleConnection类而不是通用的 OleDbConnection。这样做可能会为您提供比您现在收到的更具体的错误信息 - 并且可以帮助您更快地找到问题。

See here for more information on the System.Data.OracleClientnamespace included with the .Net framework.

有关.Net 框架中包含的System.Data.OracleClient命名空间的更多信息,请参见此处。