|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Data.OleDb;
|
|
|
|
|
using ICSharpCode.Data.Core.DatabaseObjects;
|
|
|
|
|
using ICSharpCode.Data.Core.Interfaces;
|
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.Data.Access
|
|
|
|
|
{
|
|
|
|
|
public class AccessDatasource: Datasource
|
|
|
|
|
{
|
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 程序提供者
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Provider
|
|
|
|
|
{
|
|
|
|
|
get { return GetConnectionStringSetting("Provider"); }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetConnectionStringSetting("Provider", value);
|
|
|
|
|
OnPropertyChanged("Provider");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 数据库
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Server
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return GetConnectionStringSetting("Data Source");
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetConnectionStringSetting( "Data Source" , value);
|
|
|
|
|
OnPropertyChanged( "Data Source" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Access用户名,默认Admin
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string UserId
|
|
|
|
|
{
|
|
|
|
|
get { return GetConnectionStringSetting("User Id"); }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetConnectionStringSetting("User Id", value);
|
|
|
|
|
OnPropertyChanged("UserId");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Access用户密码,默认为空
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Password
|
|
|
|
|
{
|
|
|
|
|
get { return GetConnectionStringSetting("Password"); }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetConnectionStringSetting("Password", value);
|
|
|
|
|
OnPropertyChanged("Password");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Access数据库密码
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string DataBasePassword
|
|
|
|
|
{
|
|
|
|
|
get { return GetConnectionStringSetting("Jet OLEDB:Database Password"); }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetConnectionStringSetting("Jet OLEDB:Database Password", value);
|
|
|
|
|
OnPropertyChanged("Jet OLEDB:Database Password");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
|
|
|
|
|
public AccessDatasource(IDatabaseDriver databaseDriver)
|
|
|
|
|
: base(databaseDriver)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
|
|
protected override bool HandlePopulateDatabasesException(Exception exception)
|
|
|
|
|
{
|
|
|
|
|
if (exception is OleDbException)
|
|
|
|
|
{
|
|
|
|
|
OleDbException sqlException = exception as OleDbException;
|
|
|
|
|
|
|
|
|
|
if (sqlException.ErrorCode == 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
|
|
|
|
|
}
|
|
|
|
|
}
|