Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.DbExplorer.MsSqlServer/SqlServerConnection.cs @ 7959

Last change on this file since 7959 was 7629, checked in by mkommend, 13 years ago

#1734:

  • renamed plugin files to Plugin.cs.frame to be consistent with the trunk solution
  • added dabase explorers for the sql server and oracle
File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Data.Common;
23using System.Data.SqlClient;
24using HeuristicLab.DataImporter.DbExplorer.Interfaces;
25
26namespace HeuristicLab.DataImporter.DbExplorer.MsSqlServer {
27  public class SqlServerConnection : DbConnectionBase {
28    private string constring;
29
30    public SqlServerConnection(string serverName, string databaseName, string userName, string password, bool useWindowsAuthentication)
31      : base(databaseName, userName, password) {
32      this.serverName = serverName;
33      this.useWindowsAuthentication = useWindowsAuthentication;
34
35      this.constring = "Server=" + serverName + "; Initial Catalog=" + databaseName;
36      if (useWindowsAuthentication)
37        this.constring += @"; Integrated Security=true";
38      else
39        this.constring += "; User ID=" + userName + "; Password=" + password;
40    }
41
42    private string serverName;
43    public string ServerName {
44      get { return this.serverName; }
45      set { this.serverName = value; }
46    }
47
48    private bool useWindowsAuthentication;
49    public bool UseWindowsAuthentication {
50      get { return this.useWindowsAuthentication; }
51      set { this.useWindowsAuthentication = value; }
52    }
53
54    public override DbConnection CreateConnection() {
55      return new SqlConnection(constring);
56    }
57
58    public override bool TestConnection() {
59      System.Data.Common.DbConnection con = null;
60      try {
61        con = this.CreateConnection();
62        con.Open();
63        this.ErrorMessage = "";
64        return true;
65      }
66      catch (SqlException e) {
67        this.ErrorMessage = e.Message;
68        this.CreateConnection().Close();
69        return false;
70      }
71      finally {
72        if (con != null)
73          con.Close();
74      }
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.