public static ServerVersionNumber RetrieveServerVersionFromFile(String filePath)
        {
            FileStream fStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);

            fStream.Seek(16, SeekOrigin.Begin);
            byte[] versionHeaderBytes = new byte[4];
            fStream.Read(versionHeaderBytes, 0, versionHeaderBytes.Length);
            uint versionHeader = BitConverter.ToUInt32(versionHeaderBytes, 0);

            ServerVersionNumber result = ServerVersionNumber.VERSION_UNKNOWN;

            switch (versionHeader)
            {
            case 0x002dd714:
                result = ServerVersionNumber.VERSION_3_0;
                break;

            case 0x00357b9d:
                result = ServerVersionNumber.VERSION_3_5;
                break;

            case 0x003d0900:
                result = ServerVersionNumber.VERSION_4_0;
                break;

            default:
                result = ServerVersionNumber.VERSION_UNKNOWN;
                break;
            }
            fStream.Close();

            return(result);
        }
        public bool OpenDatabase(String databasePath, String password)
        {
            CloseDatabase();
            bool result = false;

            _databasePath         = databasePath;
            ServerVersionFromFile = Utilities.RetrieveServerVersionFromFile(databasePath);
            switch (ServerVersionFromFile)
            {
            case ServerVersionNumber.VERSION_3_0:
                IDatabaseInstance = SqlServerCE3_1Database.CreateInstance(databasePath, password);
                break;

            case ServerVersionNumber.VERSION_3_5:
                IDatabaseInstance = SqlServerCE3_5Database.CreateInstance(databasePath, password);
                break;

            case ServerVersionNumber.VERSION_4_0:
                IDatabaseInstance = SqlServerCE4_0Database.CreateInstance(databasePath, password);
                break;

            default:
                break;
            }

            try
            {
                IDatabaseInstance.OpenConnection();
                if (IDatabaseInstance.ConnectionState == ConnectionState.Open)
                {
                    UpdateInfoSchemaTV();
                    result = true;
                }
                else
                {
                    CloseDatabase();
                }
            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc.Message);
            }
            return(result);
        }