简体   繁体   English

无法在 c# 中连接到 Oracle 数据库

[英]Can't make a connection to Oracle Database in c#

I'm writing a console application that requires data to be pulled from a database.我正在编写一个控制台应用程序,它需要从数据库中提取数据。 When I use the following line to create the connection object, it throws a FileNotFoundException.当我使用以下行创建连接对象时,它会引发 FileNotFoundException。

OracleConnection con = new OracleConnection();

I've installed and included the Oracle Managed Data Access Client, and I've attempted to rewrite the definition multiple ways, including passing the connection string in the definition, but it always throws the same exception.我已经安装并包含了 Oracle Managed Data Access Client,并尝试以多种方式重写定义,包括在定义中传递连接字符串,但它总是抛出相同的异常。

Here's the exact message:这是确切的消息:

System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'OracleInternal.Common.ProviderConfig' threw an exception. System.TypeInitializationException HResult=0x80131534 Message='OracleInternal.Common.ProviderConfig' 的类型初始值设定项引发异常。 Source=Oracle.ManagedDataAccess StackTrace: at Oracle.ManagedDataAccess.Client.OracleConnection..ctor(String connectionString) at SecurityAwareness.Program.Main(String[] args) in "directory" Source=Oracle.ManagedDataAccess StackTrace:在 Oracle.ManagedDataAccess.Client.OracleConnection..ctor(String connectionString) at SecurityAwareness.Program.Main(String[] args) 在“目录”

Inner Exception 1: FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.内部异常 1:FileNotFoundException:无法加载文件或程序集“System.Configuration.ConfigurationManager,Version=0.0.0.0,Culture=neutral,PublicKeyToken=cc7b13ffcd2ddd51”。 The system cannot find the file specified.该系统找不到指定的文件。

You do not mention which .NET you are using.您没有提及您使用的是哪个 .NET。 I had the same error.我有同样的错误。 I was building an app using the WebApi2, which uses the .NET Core 2.x instead of the .NET 4.x.我正在使用 WebApi2 构建一个应用程序,它使用 .NET Core 2.x 而不是 .NET 4.x。

I switched to the Oracle.ManagedDataAccess.Core (2.18) NuGet Package and then the error went away, and I was able to connect to my Oracle Database using the simple Oracle Connection code.我切换到 Oracle.ManagedDataAccess.Core (2.18) NuGet 包,然后错误消失了,我能够使用简单的 Oracle 连接代码连接到我的 Oracle 数据库。

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

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