项目需引用:Oracle.ManagedDataAccess.dll
string connectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["oracleDB"].ToString(); OracleConnection connB = new OracleConnection(connectionString); connB.Open(); Console.WriteLine("测试数据库连接成功!"); Console.WriteLine(); connB.Close();
配置文件
<add name="oracleDB" providerName="System.Data.OracleClient" connectionString="Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 9000)) ) (CONNECT_DATA =(SERVICE_NAME = orcl))); User Id=system;Password=123;" />