/////////////////////////////////////////////////////////// // 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 { /// /// Retrieves useful info about the database server /// [Serializable] public class DBInfo : ReadOnlyBase //case 570 { #pragma warning disable 1591 #region Attributes private string mVersion; /// /// Database server version /// public string Version { get { return mVersion; } } private string mDBServerType; /// /// Database server type /// public string DBServerType { get { return mDBServerType; } } private string _FingerPrint; /// /// Fingerprint of database schema /// used to determine schema corruption /// or 3rd party changes to the schema /// public string FingerPrint { get { return _FingerPrint; } set { _FingerPrint = value; } } #endregion #region Constructor /// /// Private constructor to prevent direct instantiation /// private DBInfo() { } #endregion #region Static methods public static DBInfo GetInfo() { return (DBInfo)DataPortal.Fetch(new Criteria()); } #endregion #region DAL DATA ACCESS /// /// 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 /// /// Criteria for identifying existing object /// [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