2018-07-10
這是敝人第一次試用。
環境:Visual Studio 2017 v15.7.4
Oracle Database 12c Standard 是另外一台電腦
連上官方網站,下載 ORAC for Visual Studio 2017
Oracle Data Access Components - .NET Downloads
http://www.oracle.com/technetwork/topics/dotnet/downloads/net-downloads-160392.html
(下圖) 下載
(下圖) 下載得到 ODTforVS2017_122011.exe
注意網頁上的說明,例如 Visual Studio 2017 至少要 v15.5.4 版
(下圖)
C:\Program Files (x86)\Oracle Developer Tools for VS2017\asp.net\SQL
因為敝人這台電腦有 Visual Studio 2017,但沒有 Oracle Database (在另外一台)
所以這一堆 .sql 敝人沒有執行
(下圖) 只是看一下是甚麼
(下圖) 這裡有範例
C:\Program Files (x86)\Oracle Developer Tools for VS2017\samples\odp.net.managed\4\
敝人複製一份 DataReader 目錄,拿來修改和測試
(下圖) 修改和測試
// C# using System; using System.Data; using System.Data.Common; using Oracle.ManagedDataAccess.Client; class VisibleFieldCountSample { static void Main(string[] args) { // 依照自己環境修改 string constr = "User Id=scott; Password=tiger; Data Source=oracle;"; using (OracleConnection conn = new OracleConnection(constr)) { conn.ConnectionString = constr; try { conn.Open(); OracleCommand cmd = new OracleCommand(); cmd.Connection = (OracleConnection)conn; //to gain access to ROWIDs of the table cmd.AddRowid = true; //cmd.CommandText = "select empno, ename from emp;"; cmd.CommandText = "select llevel from A;"; OracleDataReader reader = cmd.ExecuteReader(); int visFC = reader.VisibleFieldCount; //Results in 2 int hidFC = reader.HiddenFieldCount; // Results in 1 Console.WriteLine("Visible field count: " + visFC); Console.WriteLine("Hidden field count: " + hidFC); reader.Dispose(); cmd.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } } } } |
ORA-12504: TNS:未提供監聽器 CONNECT_DATA 中的 SERVICE_NAME
(下圖) 查了一下,要修改組態檔案
C:\Program Files (x86)\Oracle Developer Tools for VS2017\network\admin\tnsnames.ora
(下圖) 新增一筆組態,請依照自己環境修改
Data Source 的值是 (資料來源別名)?
(資料來源別名) =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 資料庫主機IP或網址 )(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = 服務名稱)
)
)
(下圖) 只是看一下,沒有修改
(下圖) 執行成功
********************************************************************************
如果是自己另另外建立的方案
********************************************************************************
如果要在 Web.Config 中加入 Oracle Database 連線字串
<add name="oracleConnectionString" connectionString="User Id=帳號; Password=密碼; Data Source=來源IP;Persist Security Info=True;" providerName="System.Data.OracleClient" /> |
(完)
相關
Oracle Data Access Components - .NET Downloads
http://www.oracle.com/technetwork/topics/dotnet/downloads/net-downloads-160392.html
Data Provider for .NET Developer's Guide
https://docs.oracle.com/database/121/ODPNT/client.htm#ODPNT0008
官方範例
https://docs.oracle.com/database/121/ODPNT/OracleConnectionClass.htm#ODPNT758
Oracle SQL Developer
https://www.oracle.com/database/technologies/appdev/sql-developer.html
System.Data.OracleClient Namespace
https://msdn.microsoft.com/en-us/library/system.data.oracleclient(v=vs.110).aspx
.Net 開發者與 Oracle Database (六)
https://dotblogs.com.tw/chhuang/2012/06/17/72862
Oracle .NET 开发人员中心
2016 年 10 月 6 日更新
http://www.oracle.com/technetwork/cn/topics/dotnet/whatsnew/index.html
Oracle .NET Developer Center
https://www.oracle.com/database/technologies/appdev/dotnet.html
Oracle's Commitment to .NET
http://images.slideplayer.com/19/5843029/slides/slide_5.jpg
Fundamentals of Database Chapter 7 Database Technologies.
https://slideplayer.com/slide/7457134/
Getting Started with Oracle and.NET Christian Shay Principal Product Manager,.NET and Windows Oracle USA.
https://slideplayer.com/slide/5843029/
C# - Oracle - How To Connect C# with Oracle Using ODAC - ODP.NET
https://www.youtube.com/watch?v=cP6UatAZ76s
沒有留言:
張貼留言