Files
2018-06-29 19:47:36 +00:00

207 lines
5.5 KiB
C#

///////////////////////////////////////////////////////////
// Bool.cs
// Implementation of Class DBInfo
// CSLA type: Read-only object
// Created on: 26-Dec-2008
// Object design: John
// Coded: John 26-Dec-2008
///////////////////////////////////////////////////////////
using System;
using System.Data;
using CSLA.Data;
using GZTW.Data;
using CSLA;
using System.Threading;
using CSLA.Security;
using System.ComponentModel;
namespace GZTW.AyaNova.BLL
{
/// <summary>
/// Retrieves useful info about the database server
/// </summary>
[Serializable]
public class DBInfo : ReadOnlyBase //case 570
{
#pragma warning disable 1591
#region Attributes
private string mVersion;
/// <summary>
/// Database server version
/// </summary>
public string Version
{
get { return mVersion; }
}
private string mDBServerType;
/// <summary>
/// Database server type
/// </summary>
public string DBServerType
{
get { return mDBServerType; }
}
private string _FingerPrint;
/// <summary>
/// Fingerprint of database schema
/// used to determine schema corruption
/// or 3rd party changes to the schema
/// </summary>
public string FingerPrint
{
get { return _FingerPrint; }
set { _FingerPrint = value; }
}
#endregion
#region Constructor
/// <summary>
/// Private constructor to prevent direct instantiation
/// </summary>
private DBInfo()
{
}
#endregion
#region Static methods
public static DBInfo GetInfo()
{
return (DBInfo)DataPortal.Fetch(new Criteria());
}
#endregion
#region DAL DATA ACCESS
///
/// <param Bool="Criteria"></param>
protected override void DataPortal_Fetch(object Criteria)
{
Criteria crit = (Criteria)Criteria;
string q = "";
try
{
#region server type and version
DataBaseType currentdbtype = DBUtil.DB.DBType;
if (currentdbtype == DataBaseType.MSSQL)
{
q = "select SERVERPROPERTY('PRODUCTVERSION')";
mDBServerType = "MSSQL";
mVersion = System.Convert.ToString(DBUtil.GetScalarFromSQLString(q));
}
else if (currentdbtype == DataBaseType.FireBird)
{
q = "SELECT rdb$get_context('SYSTEM', 'ENGINE_VERSION') from rdb$database";
mDBServerType = "FireBird";
//case 1082, apparently the above doesnt' query the server itself, it checks variables stored in the database
//so unless the db was created with FB 2.x tools it will barf when the query is run which is trouble for AyaNova
//3.x people updating.
//since this is buggy, I'm removing it for now entirely as there is no consistent safe way to check the db server
//version, the thrust of this was more aimed at SQL server anyway.
mVersion = "Unknown";
//try
//{
// mVersion = System.Convert.ToString(DBUtil.GetScalarFromSQLString(q));
//}
//catch (Exception ex)
//{
// mVersion = "unknown";
//}
}
#endregion server type and version
#region fingerprint
_FingerPrint = DBUtil.DB.SchemaFingerPrint;
//if (currentdbtype == DataBaseType.FireBird)
//{
// using (IDbConnection cn = DBUtil.DB.GetConnection())
// {
// cn.Open();
// }
// try
// {
// }
// catch (Exception ex)
// {
// FingerPrint = "Error: " + ex.Message;
// throw;
// }
// finally
// {
// if (cn != null)
// cn.Close();
// }
//}
//else if (currentdbtype == DataBaseType.MSSQL)
//{
// //q = "select SERVERPROPERTY('PRODUCTVERSION')";
// _FingerPrint = "blah";
//}
#endregion
}
catch (Exception ex)
{
mVersion = "Error: Can't retrieve database server version, likely an old unsupported version, error was:\r\n " + ex.Message;
}
}
#endregion
#region criteria
/// <summary>
/// Criteria for identifying existing object
/// </summary>
[Serializable]
private class Criteria
{
//public Guid ReportID;
public Criteria( /*Guid _ReportID*/)
{
//ReportID=_ReportID;
}
}
#endregion
#pragma warning restore 1591
}//end class
}//end namespace GZTW.AyaNova.BLL