OracleConnection.open()仅在调试器中成功,而不是通过可执行文件成功 [英] OracleConnection.open() successful only in debugger, not through executable
问题描述
我是Oracle的新手,我遇到了一个问题.当我从IDE-Visual Studio 2005运行该应用程序时,数据库连接建立得很顺利,但是当我运行该应用程序的已安装版本时,数据库连接失败并且出现了TNS:发生连接超时错误.
我尝试使用SQLNET.ORA和在线找到的类似解决方案,但无法解决该问题.我不知道为什么会这样,因为通过IDE和安装运行的应用程序在同一台PC上.我确保正确编辑了TNSNAMES.ORA文件,并且可以通过直接在Visual Studio上运行的应用程序实例进行连接.
连接功能的代码如下.当我通过VS2005 [F5]运行时,我可以很好地连接,但是当我安装与可执行文件相同的代码时,则无法连接.到目前为止,我已经尝试并未能解决它.任何见解将不胜感激,我没有想法,很快就没时间了. :((
I am new to Oracle, and there is an issue I am facing. When I run the application from IDE - Visual Studio 2005, The database connection is established smoothly, but when I run an installed version of the app, the DB connection fails and I get a TNS: Connect timeout occurred error.
I tried with SQLNET.ORA and similar solutions found online, but I could not resolve the issue. I wonder why this happens, since the application running through the IDE and through an installation is on the same PC. I made sure the TNSNAMES.ORA file was correctly edited, and I can connect through an instance of the application running directly on Visual Studio.
The code for the connect function is as below. I am able to connect fine when I run through VS2005 [F5] but not when I install the same code as an executable. So far I have tried and failed to resolve it. Any insight would be appreciated, I am out of ideas and fast running out of time. :((
public bool connectToDatabase(string dbConnStr)
{
try
{
databaseConnection = dbConnStr;
OracleConnection dbConn = new OracleConnection(databaseConnection);
if (dbConn == null)
{
CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, "Connection object is null");
return false;
}
if (dbConn.State.ToString().Equals("Closed", StringComparison.OrdinalIgnoreCase))
{
CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, "DB connection - " + dbConn.ConnectionString);
dbConn.Open();
return true;
}
}
catch (Exception ex)
{
CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, ex.Message + "\n" + ex.StackTrace);
CreateDLLLogFiles.ErrorLog(CreateDLLLogFiles.FileName, "DB String - " + databaseConnection);
return false;
}
return false;
}
堆栈跟踪如下:
The stack trace is as below:
7/22/2010 6:38:51 PM ORA-12170: TNS:Connect timeout occurred
at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src)
at Oracle.DataAccess.Client.OracleConnection.Open()
at SQL.connectToDatabase(String dbConnStr)
tnsnames.ora文件如下所示,尽管由于可以从Visual Studio连接,所以可以放心地说,此文件已正确编辑.
The tnsnames.ora file is as below, although since I can connect from Visual Studio, I can safely say that this is correctly edited.
MySource =
(DESCRIPTION =
(CONNECT_TIMEOUT=180)(RETRY_COUNT=2)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 125.63.77.232)(PORT = 1521)))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = MySource )
)
)
任何帮助表示赞赏.提前谢谢.
-Sreedevi.
Any help is appreciated. Thanks in advance.
-Sreedevi.
推荐答案
问题已解决.非常感谢大家的帮助! :)原来是损坏的ODAC DLL的组合,然后是一些.
干杯!
Issue was resolved. Thank you very much for your help, everyone! :) Turned out to be a combination of corrupted ODAC Dlls and then some.
Cheers!
这篇关于OracleConnection.open()仅在调试器中成功,而不是通过可执行文件成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!