C# Oracle Data Provider for .NET 資料庫連線
RojerChen.2014.12.18
C# 要連接 Oracle 資料庫其實還蠻簡單的,記得以前要安裝有的沒有的軟體,然後再參考 DLL 檔案才有辦法透過 Oledb 連資料庫,現在有了 NuGet 後,只要安裝一下 Oracle Data Provider for .NET 就可以連 Oracle 資料庫了。
SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID))); uid=myUsername;pwd=myPassword;
再來參考
using Oracle.ManagedDataAccess.Client;
string ConnectString = "Your Connection String"; OracleConnection Conn = new OracleConnection(); Conn.ConnectionString = ConnectString; try { Conn.Open(); OracleCommand cmd = new OracleCommand(); cmd.CommandText = "select * from table1"; cmd.Connection = Conn; OracleDataReader dr = cmd.ExecuteReader(); string txt = string.Empty; while (dr.Read()) { Console.Write(dr["column"].ToString()); } dr.Close(); } catch (Exception ex) { Console.WriteLine(string.Format("Exception:{0}", ex.Message.ToString())); } finally { Conn.Close(); }
0 意見:
張貼留言