using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using ICSharpCode.Data.Core.DatabaseObjects; using ICSharpCode.Data.Core.Interfaces; namespace ICSharpCode.Data.PI { public class PIDatasource : Datasource { #region Fields //private SQLServerControlPanel _controlPanel = null; #endregion #region Properties public string Server { get { //get的值!=set的值 return GetConnectionStringSetting( "Data Source" ); } set { SetConnectionStringSetting( "Data Source" , value.Replace(":",",") ); OnPropertyChanged( "Data Source" ); } } public string UserId { get { return GetConnectionStringSetting("User Id"); } set { SetConnectionStringSetting("User Id", value); OnPropertyChanged("UserId"); } } public string Password { get { return GetConnectionStringSetting("Password"); } set { SetConnectionStringSetting("Password", value); OnPropertyChanged("Password"); } } public bool IntegratedSecurity { get { if (GetConnectionStringSetting("Integrated Security") == "SSPI") return true; else return false; } set { if (value) SetConnectionStringSetting("Integrated Security", "SSPI"); else SetConnectionStringSetting("Integrated Security", null); OnPropertyChanged("IntegratedSecurity"); } } public string InitialCatalog { get { return GetConnectionStringSetting("Initial Catalog", "master"); } set { SetConnectionStringSetting("Initial Catalog", value); OnPropertyChanged("Initial Catalog"); } } #endregion #region Constructor public PIDatasource(IDatabaseDriver databaseDriver) : base(databaseDriver) { } #endregion #region Methods protected override bool HandlePopulateDatabasesException(Exception exception) { if (exception is SqlException) { SqlException sqlException = exception as SqlException; if (sqlException.Number == 67) { DatabaseDriver.RemoveDatasource(Name); ICSharpCode.Core.LoggingService.Error("尝试填充数据库错误。\n\n" + exception.Message); //MessageBox.Show("Error while trying to populate databases.\n\n" + exception.Message, DatabaseDriver.Name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } else { throw exception; } } else if (exception is NotSupportedException) { DatabaseDriver.RemoveDatasource(Name); ICSharpCode.Core.LoggingService.Error("尝试填充数据库错误。\n\n" + exception.Message); //MessageBox.Show("Error while trying to populate databases.\n\n" + exception.Message, DatabaseDriver.Name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } else { throw exception; } } #endregion } }