简体   繁体   English

Oracle找不到类型或名称空间名称Oracle缺少指令

[英]Type or namespace name Oracle could not found Missing Directive

I want to build simple console application in C#.Net which will take name of table as argument and display all the data in that table. 我想在C#.Net中构建简单的控制台应用程序,它将表名称作为参数并显示该表中的所有数据。 So I write the following code in C# 所以我用C#编写了以下代码

using System;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;

namespace Ass1Que1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // Please replace the connection string attribute settings
                string constr = "DATA SOURCE=localhost:1521/orclpdb;PERSIST SECURITY INFO=True;USER ID=HR;password=hr";

                OracleConnection con = new OracleConnection(constr);
                con.Open();
                Console.WriteLine("Connected to Oracle Database {0}", con.ServerVersion);
                // con.Dispose();
                OracleCommand cmd = con.CreateCommand();
                cmd.CommandText = "SELECT FIRST_NAME FROM EMPLOYEES";
                OracleDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Console.WriteLine("" + reader.GetString(0));
                }
                Console.WriteLine("Press RETURN to exit.");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : {0}", ex);
                Console.ReadKey();
            }
        }
    }
    }

But I am getting error as 但是我得到了错误

 type or namespace name Oracle could not found. 

I know I have to add some dll reference but I dont know how to do that. 我知道我必须添加一些dll参考,但是我不知道该怎么做。 Please suggest me how to get this from error. 请建议我如何从错误中获取此信息。

Thanks in advance! 提前致谢!

You need to add a reference to the DLL that contains the Oracle.ManagedDataAccess namespace. 您需要添加对包含Oracle.ManagedDataAccess命名空间的DLL的引用。 It appears that is part of the "Oracle Data Provider for .NET, Managed Driver" provided by Oracle (link: https://docs.oracle.com/database/121/ODPNT/installODPmd.htm#ODPNT8149 ) 它似乎是Oracle提供的“ .NET的Oracle数据提供程序,托管驱动程序”的一部分(链接: https : //docs.oracle.com/database/121/ODPNT/installODPmd.htm#ODPNT8149

The easiest way to do that (assuming you are using Visual Studio) is to right-click on your Project in the Solution Explorer and select "Manage NuGet Packages". 最简单的方法(假设您使用的是Visual Studio)是在解决方案资源管理器中右键单击您的项目,然后选择“管理NuGet程序包”。 Then Browse to find the "ODP.NET, Managed Driver", and add it to your project. 然后浏览找到“ ODP.NET,托管驱动程序”,并将其添加到您的项目中。

Alternatively, you can manually install the Oracle Data Provider for .NET onto your machine, then right-click the "References" entry under your project, and select "Add Reference". 或者,您可以手动将Oracle Data Provider for .NET安装到计算机上,然后右键单击项目下的“引用”条目,然后选择“添加引用”。 From here, browse to find the "Oracle.ManagedDataAccess.dll" on your filesystem, and add the reference to that. 在这里,浏览找到文件系统上的“ Oracle.ManagedDataAccess.dll”,并添加对该文件的引用。 It should be in "ORACLE_BASE\\ORACLE_HOME\\odp.net\\bin\\4". 它应该在“ ORACLE_BASE \\ ORACLE_HOME \\ odp.net \\ bin \\ 4”中。

Hope this helps 希望这可以帮助

You are missing to add the built in oracle reference dll provided by the .net framework. 您缺少添加.net框架提供的内置oracle参考dll的功能。

  • Add it ,if you are in Visual studio 2015 right click on References -> Add References . 添加它,如果您在Visual Studio 2015中,请右键单击“ 引用” ->“ 添加引用”

在此处输入图片说明 Now use the referenced dll in your code file by using statement 现在,通过使用语句中使用的参考DLL在你的代码文件

在此处输入图片说明

Green squiggly is a warning sign not to use the obsolete method. 弯曲的绿色是不使用过时方法的警告标志。

This will resolve the Oracle connection issue but you also need to download and install Oracle.ManagedDataAccess via nuget 这将解决Oracle连接问题,但您还需要通过nuget下载并安装Oracle.ManagedDataAccess。

暂无
暂无

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

相关问题 找不到类型或名称空间名称(缺少使用指令或程序集引用吗?) - Type or namespace name could not be found (missing using directive or assembly reference?) 找不到类型或名称空间名称“ My_Interface_Name”(您是否缺少using指令或程序集引用?) - The type or namespace name 'My_Interface_Name' could not be found (are you missing a using directive or an assembly reference?) 无法找到类型或命名空间名称“oracle”错误 - The type or namespace name 'oracle' could not be found error 找不到类型或名称空间名称“ FacebookSessionClient”(您是否缺少using指令或程序集引用?) - The type or namespace name 'FacebookSessionClient' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或命名空间名称'SignInManager'(您是否缺少using指令或程序集引用?) - The type or namespace name 'SignInManager' could not be found (are you missing a using directive or an assembly reference?) 错误 CS0246:找不到类型或命名空间名称“IWebHostEnvironment”(您是否缺少 using 指令或程序集引用?) - error CS0246: The type or namespace name 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或名称空间名称“ PrintDocument”(是否缺少using指令或程序集引用?) - The type or namespace name 'PrintDocument' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或命名空间名称“OleDbConnection”(您是否缺少 using 指令或程序集引用?) - The type or namespace name 'OleDbConnection' could not be found (are you missing a using directive or an assembly reference?) 为什么会出现这个错误? “找不到类型或名称空间名称'c'(您是否缺少using指令或程序集引用?)” - Why this error ? “The type or namespace name 'c' could not be found (are you missing a using directive or an assembly reference?)” .NET Crystal Report错误:找不到类型或名称空间名称'ReportDocument'(您是否缺少using指令或程序集引用…?) - .NET Crystal Report Error : The type or namespace name 'ReportDocument' could not be found (are you missing a using directive or an assembly ref…?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM