#region License Information /* HeuristicLab * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Data.OracleClient; using HeuristicLab.DataImporter.DbExplorer.Interfaces; namespace HeuristicLab.DataImporter.DbExplorer.Oracle { public class OracleConnection : DbConnectionBase { private string constring; public OracleConnection(string databaseName, string userName, string password) : base(databaseName, userName, password) { this.constring = "Server=" + databaseName; this.constring += "; User ID=" + userName + "; Password=" + password; } public OracleConnection(string host, string port, string serviceName, string userName, string password) : base(host, userName, password) { this.constring = String.Format("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0}) (PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})))" + ";User Id={3};Password={4};", host, port, serviceName, userName, password); } public override System.Data.Common.DbConnection CreateConnection() { return new System.Data.OracleClient.OracleConnection(constring); } public override bool TestConnection() { System.Data.Common.DbConnection con = null; try { con = this.CreateConnection(); con.Open(); this.ErrorMessage = ""; return true; } catch (OracleException e) { this.ErrorMessage = e.Message; this.CreateConnection().Close(); return false; } finally { if (con != null) con.Close(); } } } }