You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
3.8 KiB
C#

// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
#region Usings
using ICSharpCode.Data.Core.DatabaseObjects;
using ICSharpCode.Data.Core.Interfaces;
using System.Threading;
using System;
using System.Data.SqlClient;
#endregion
namespace ICSharpCode.Data.Core.DatabaseDrivers.SQLServer
{
public class SQLServerDatasource : 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 SQLServerDatasource(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
}
}