Oracle ASP.NET:TNSの問題
質問
ASP.net/c#でDB Oracleに接続しようとしています。
これが私のコードです:
OracleConnection connection = new OracleConnection();
connection.ConnectionString = @"Data Source=ORACLEDB;User id=me;Password=xxxx;";
try
{
connection.Open();
}
catch (Exception ex)
{
Console.WriteLine("Exception occurs when connecting to DB : " + ex.Message + ex.StackTrace);
}
そして、これが私が得るエラーです:
ORA-12154: TNS : the identifier could not be solved
これが私のtnsnames.oraです:
ORACLEDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = myComputer.myDomain)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = ORACLEDB)
)
)
Win2K3サーバーR2に取り組んでいます。
Oracleは同じサーバーにあります。 Oracle 11gです。
私がtnspingをするとき、私はこれを手に入れます:
EZCONNECT adapter used to resolved the alias
Tentative de contact de (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=169.254.216.123)(PORT=1521)))
OK (20 msec)
そして、これが私のリスナーです。ORA:
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\app\Administrator\product\11.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:C:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll")
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = myComputer.myDomain)(PORT = 1521))
)
)
解決
文字列接続をweb.configに入れます:
<connectionStrings>
<add name="OracleDatabase"
connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME= ORACLEDB)));User Id= me;Password= xxx;Persist Security Info=True;"
providerName="System.Data.OracleClient" />
</connectionStrings>
次に、web.configから接続文字列を取得します。
connection.ConnectionString = ConfigurationManager.ConnectionStrings["OracleDatabase"].ConnectionString;
他のヒント
tnspingを使用して問題を診断してみてください。 Oracle Home/Bin Directoryにあるユーティリティです。
ezconnectアダプターとは何ですか?たぶんtnspingとあなたのコードは異なるドライバーを使用していますか?
コードの接続文字列にデータベースのIPアドレスを使用してみてください。これは、問題の原因を示すかもしれません。
mycomputer.mydomainを接続文字列のデータソースとして使用しようとすると、エラーコードが表示されます
ORA-12504 : TNS : the listener processus didn't obtain SERVICE_NAME in CONNECT_DATA
.
idk ezconnectは何ですか:-)
Command tnsping localhostはこれを示します。
C:\app\Administrator\product\11.2.0\dbhome_1\network\admin\sqlnet.ora
Adaptateur TNSNAMES utilisé pour la résolution de l'alias
Tentative de contact de (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = myComputer.myDomain)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = ORACLEDB)))
OK (20 msec)
たぶんそれは役立つかもしれません:SQL Plusを使用してDBを接続しようとすると、それは正常に動作します...
どうもありがとうございました。
所属していません StackOverflow