close
目的為將舊的Windows 2003 x86的網站移到新的Windows 2012 x64網站,因無法連線Linux ORACLE 9i,花了一大堆時間,提供給大家參考的過程

 

1. windows 2012 x64安裝了Oracle Database 11g Release 2 Client (11.2.0.1.0) for Microsoft Windows x64 (64-bit),安裝過程的軟體位置目錄為d:\app\UserName\product\11.2.0\client_1

 

2. 將tnsnames.ora複製到安裝client目錄的d:\app\UserName\product\11.2.0\client_1\network\admin\

 

3. 使用其Oracle Net Manager測試連線,可以完成測試連線到Linux ORACLE 9i主機。

 

4. 跑原來的asp程式,出現「500-內部伺服器錯誤。」

 

5. 站台建立bin目錄,將32bitsSystem.Data.OracleClient.dll放入,跑ASP.NET  .aspx程式,測試連線Linux ORACLE 9i主機,出現錯誤「Could not load file or assembly 'System.Data.OracleClient' or one of its dependencies. An attempt was made to load a program with an incorrect format.

 

6. 將C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Data.OracleClient.dll64bit System.Data.OracleClient.dll放到站台的bin目錄,測試也失敗。

 

7. 以上的問題,花了2天找尋IIS8 x64連結Oracle的方法,快吐血,終於爬文到http://www.blueshop.com.tw/board/FUM20041006161839LRJ/BRD20130226144334IJA.html,才想說死馬當活馬醫,再加裝32-bitclient試試。

 

8. 再安裝Oracle Database 11g Release 2 Client (11.2.0.1.0) for Microsoft Windows (32-bit),安裝過程的軟體位置目錄為d:\app\UserName\product\11.2.0\client_2

 

9. 將tnsnames.ora複製到安裝client目錄的d:\app\UserName\product\11.2.0\client_2\network\admin\

 

10. 使用Oracle Net Manager測試連線,也可以完成測試連線到Linux ORACLE 9i主機。

 

11. IIS管理員應用程式集區右邊找到此站台使用的集區名稱按右鍵,選進階設定。「啟用32位元應用程式」改設為True。從IIS管理員重新啟動WEB伺服器。

 

12. 測試asp程式,沒問題了。

 

13. 測試ASP.NET  .aspx程式,用32bitSystem.Data.OracleClient.dll,也沒問題了。

 

14. 測試ASP.NET  .aspx程式,用64bitSystem.Data.OracleClient.dll,也沒問題了。

 

15. 將應用程式集區的「啟用32位元應用程式」設為False,測試asp程式就失敗了。出現「500-內部伺服器錯誤。」

 

16. 以上測試,不管應用程式集區有無設立啟用32位元應用程式,ASP.NET都可以正常連到Linux ORACLE 9i取資料,有啟用32位元應用程式則須放入32bitSystem.Data.OracleClient.dll,沒啟用32位元應用程式則須放入64bitSystem.Data.OracleClient.dll如果是要跑傳統ASP就一定要設定為啟用32位元應用程式。

 

17. 結論是,裝了64bit oracle client32bit oracle client,再將「啟用32位元應用程式」設為True,站台的bin目錄放入32bitSystem.Data.OracleClient.dll,則該站台裡的ASPASP.NET都可以連到ORACLE

 

18. 願大家都不要走太多的冤枉路。

 

ASP測試:

<%

'ORACLE連線測試

Dim objConn_Oracle, strConnOracle, strSQL, rstOCC

Set objConn_Oracle = Server.CreateObject("ADODB.Connection")

strConnOracle = "Provider=OraOLEDB.Oracle;Data Source=MYTEST_192.168.1.1;Persist Security Info=False;User ID=USERID;Password=USERPASSWORD;"

 

objConn_Oracle.ConnectionString = strConnOracle

objConn_Oracle.Open

Dim rs

Set rs = Server.CreateObject("ADODB.Recordset")

SQLT="select * from test.test1_file"

rs.CursorLocation=3

rs.Open SQLT, objConn_Oracle, 1, 3, 1

record_num=rs.recordcount

Response.Write (" " & record_num & " <br>")

Do while not rs.EOF

account_id=rs("test01")

Response.Write (account_id & "<br>")

rs.MoveNext

LOOP

objConn_Oracle.Close

%>

 

 

ASP.NET測試

using System;

using System.Data;

using System.Data.OracleClient;

 

public partial class test1 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

string myConnString = "Data Source=MYTEST_192.168.1.1;User Id=USERID;Password=USERPASSWORD;Integrated Security=no;";

OracleConnection myConnection = new OracleConnection(myConnString);

//讀取資料------------------------------

string mySelectQuery = "SELECT * FROM test.test1_file";

OracleCommand myCommand = new OracleCommand(mySelectQuery, myConnection);

string r_1 = null;

myConnection.Open();

OracleDataReader myReader = myCommand.ExecuteReader();

try {

while (myReader.Read()) {

r_1 = myReader.GetString(0);

Label99.Text += r_1 + "<br>";

}

}

finally {

myReader.Close();

myConnection.Close();

}

}

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 adamschen9921 的頭像
    adamschen9921

    昶達的部落格

    adamschen9921 發表在 痞客邦 留言(1) 人氣()