时间:2021-07-01 10:21:17 帮助过:16人阅读
注意:Path 中设置的 路径一定要放在oracle 的路径前面, 记得修改 instantclient_11_2 文件夹E:\app\instantclient_11_2\network\ADMIN\tnsnames.ora 文件里面的配置信息
tnsnames.ora 文件:
1 # TNSNAMES.ORA Network Configuration File: C:\oracle\ora90\network\admin\tnsnames.ora 2 # Generated by Oracle configuration tools. 3 4 #sample 5 6 #DATABASENAME = 7 # (DESCRIPTION = 8 # (ADDRESS_LIST = 9 # (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521)) 10 # ) 11 # (CONNECT_DATA = 12 # (SERVICE_NAME = servicename) 13 # ) 14 # ) 15 16 orcl= 17 (DESCRIPTION = 18 (ADDRESS_LIST = 19 (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT =1521)) 20 ) 21 (CONNECT_DATA = 22 (SERVICE_NAME =orcl) 23 ) 24 )
测试代码如下:
1 public class SqlHelper 2 { 3 private static string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ToString(); 4 public static DataTable Query(string sql) 5 { 6 DataTable dt = new DataTable(); 7 using (OracleConnection conn = new OracleConnection(connStr)) 8 { 9 conn.Open(); 10 OracleCommand cmd = new OracleCommand(sql,conn); 11 OracleDataAdapter adapter = new OracleDataAdapter(cmd); 12 adapter.Fill(dt); 13 return dt; 14 } 15 } 16 }
配置文件 config
1 <configuration> 2 <connectionStrings> 3 <add name="connStr" connectionString="Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)
(HOST = localhost)(PORT =1521)))(CONNECT_DATA =(SERVICE_NAME =orcl)));user=***; password=******;
persist security info=false;Min Pool Size=10;Max Pool Size=100;Pooling=true;" />
<!--<add name="connStr" connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)));User Id=***;Password=***;"/>--> 4 </connectionStrings> 5 <system.web> 6 <compilation debug="true" targetFramework="4.5" /> 7 <httpRuntime targetFramework="4.5" /> 8 </system.web> 9 10 </configuration>
尝试加载 Oracle 客户端库时引发 BadImageFormatException。如果在安装 32 位 Oracle 客户端组件的情况下以 64 位模式运行,将出现此问题。
标签:amp admin pass -- ati address 安装 正是 names