以下是我的配置文件
<configuration>
<configSections>
<section name="Oracle.ManagedDataAccess.Client"
type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="DBNAME" connectionString="User Id=USERNAME; Password=PASSWORD; Data Source=DEV01" providerName="Oracle.ManagedDataAccess.Client"/>
</connectionStrings>
<oracle.manageddataaccess.client>
<version number="4.121.1.0">
<dataSources>
<dataSource alias="DEV01" descriptor="(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = HOST)(PORT = PORT))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = dev01.local.junk)))" />
</dataSources>
</version>
</oracle.manageddataaccess.client>
</configuration>
我的tnsnames.ora中也有描述符。我能够tnsping dev01,它使连接很好。我也可以直接将描述符放入硬编码数据摘要的连接字符串中,并且它连接到DB就好了。有些问题,而且tnsnames似乎没有其他工作。我觉得它在我的配置文件中有些东西,但似乎无法弄明白。
编辑:
通过
从代码中读取if (_configReader != null)
{
_connectionString =
_configReader.ConnectionStringsSection.ConnectionStrings["DBNAME"].ConnectionString;
}
OracleConnection connection = new OracleConnection(_connectionString);
connection.Open();
返回上面的连接字符串
答案 0 :(得分:1)
在您的描述符中,您似乎没有关闭所有括号。我不认为你在那里需要address_list ...尝试使用
(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = HOST)(PORT = PORT))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = dev01.local.junk)))
编辑:
终于找到了问题。首先,您的manageddataaccess的部分名称是小写的,否则它将不匹配。其次,我不确定你的_configReader是什么,但我只是使用了System.Configuration.Configuration对象,它就像这样:
// Get the application configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
if (config != null)
{
ConnectionStringSettings settings = new ConnectionStringSettings("DEV01", config.ConnectionStrings.ConnectionStrings["DBNAME"].ToString());
OracleConnection connection = new OracleConnection(settings.ConnectionString);
connection.Open();
}
我对配置文件所做的唯一更改是将节名称值更改为小写。