[英]Type or namespace name could not be found (missing using directive or assembly reference?)
[英]Type or namespace name Oracle could not found Missing Directive
我想在C#.Net中構建簡單的控制台應用程序,它將表名稱作為參數並顯示該表中的所有數據。 所以我用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();
}
}
}
}
但是我得到了錯誤
type or namespace name Oracle could not found.
我知道我必須添加一些dll參考,但是我不知道該怎么做。 請建議我如何從錯誤中獲取此信息。
提前致謝!
您需要添加對包含Oracle.ManagedDataAccess命名空間的DLL的引用。 它似乎是Oracle提供的“ .NET的Oracle數據提供程序,托管驅動程序”的一部分(鏈接: https : //docs.oracle.com/database/121/ODPNT/installODPmd.htm#ODPNT8149 )
最簡單的方法(假設您使用的是Visual Studio)是在解決方案資源管理器中右鍵單擊您的項目,然后選擇“管理NuGet程序包”。 然后瀏覽找到“ ODP.NET,托管驅動程序”,並將其添加到您的項目中。
或者,您可以手動將Oracle Data Provider for .NET安裝到計算機上,然后右鍵單擊項目下的“引用”條目,然后選擇“添加引用”。 在這里,瀏覽找到文件系統上的“ Oracle.ManagedDataAccess.dll”,並添加對該文件的引用。 它應該在“ ORACLE_BASE \\ ORACLE_HOME \\ odp.net \\ bin \\ 4”中。
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.