現象
"new OracleConnection" がやたらと重い。
Oracleデータベースへの接続が重いわけではない。
sqlplusコマンドによるログインは1秒以内で完了。
Visual Studio からのデバッグ実行 (F5) 時のコンストラクト (new OracleConnection) も1秒以内で完了。
通常実行 (Ctrl+F5) 時のコンストラクト (new OracleConnection) だけが重い。30秒以上かかる。
謎。すごい謎。
コード
string datasource = "localhost"; string name = "hoge"; string pass = "hoge"; string path = String.Format("User Id={0};password={1};Data Source={2}", name, pass, datasource); OracleConnection con = new OracleConnection(path); // ここが糞重い g_con.Open();
調査
creation of new OracleConnection VERY SLOW in V... | Oracle Community
Solution: (works and it's repeatable for me)
Create C:\app\alexandrescup\product\11.1.0\client_1\log\diag\clients folder.
oracle - Creating 32-bit ODP.Net OracleConnection object is very slow - Stack Overflow
Try creating the "log\diag\clients" directory structure in your Oracle home. See this blog post - the blogger had the same problem you had and resolved it by creating that directory structure.
geoffhudik.com - Tech - Slow OracleConnection Creation
To resolve the error I had to create the folder structure "log\diag\clients" in my "C:\app\username\product\11.2.0\client_2\" directory.
log\diag\clients フォルダを作ることが定番の対策らしい。なんじゃそりゃ。
しかし該当フォルダ作ってみても解決しない。
対策
Visual Studio の該当プロジェクトからは 11.2.0 に付属の Oracle.DataAccess.dll (ファイルバージョン 2.112.2.0) を参照するように変更した。
結果、"new OracleConnection" がやたらと重い問題は解決した。
参考:DLLバージョン確認方法
ファイルのプロパティとか Visual Studio 上のプロパティウィンドウとかで確認する。