Beispiel #1
0
        internal DBVersionInfo GetDBVersion(IDbConnection connection)
        {
            if (dbVersion == null)
            {
                dbVersion = FetchDBServerInfo(connection);
            }

            return(dbVersion);
        }
Beispiel #2
0
        public override DBVersionInfo FetchDBServerInfo(IDbConnection connection)
        {
            //select sqlite_version();
            if (connection == null)
            {
                throw new Exception("Required valid connection object to initialise database details");
            }

            string query     = @"SELECT sqlite_version();";
            bool   isConOpen = connection.State == ConnectionState.Open;

            try
            {
                if (!isConOpen)
                {
                    connection.Open();
                }

                IDbCommand command = connection.CreateCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = query;

                DBVersionInfo dbVersion = new DBVersionInfo();

                using (IDataReader rdr = command.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        dbVersion.ProductName = "SQLite";
                        dbVersion.Version     = new Version(rdr.GetString(0));

                        //dbVersion.Is64Bit = true;
                    }
                    rdr.Close();
                }

                return(dbVersion);
            }
            catch
            {
                //ignore error
                return(null);
            }
            finally
            {
                if (!isConOpen && connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
        }
Beispiel #3
0
        public override DBVersionInfo FetchDBServerInfo(IDbConnection connection)
        {
            if (connection == null)
            {
                throw new Exception("Required valid connection object to initialise database details");
            }

            string query     = @"SELECT SERVERPROPERTY('Edition') AS Edition,SERVERPROPERTY('ProductVersion') AS ProductVersion;";
            bool   isConOpen = connection.State == ConnectionState.Open;

            try
            {
                if (!isConOpen)
                {
                    connection.Open();
                }

                IDbCommand cmd = connection.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = query;

                using (IDataReader rdr = cmd.ExecuteReader())
                {
                    DBVersionInfo dbVersion = new DBVersionInfo();
                    if (rdr.Read())
                    {
                        dbVersion.ProductName = "Microsoft SQL Server";
                        dbVersion.Edition     = rdr.GetString(0);
                        dbVersion.Version     = new Version(rdr.GetString(1));

                        //https://sqlserverbuilds.blogspot.in/
                        //https://support.microsoft.com/en-in/help/321185/how-to-determine-the-version--edition-and-update-level-of-sql-server-a
                        if (dbVersion.Version.Major == 14)
                        {
                            dbVersion.ProductName += "2017 " + rdr.GetString(0);
                        }
                        else if (dbVersion.Version.Major == 13)
                        {
                            dbVersion.ProductName += "2016 " + rdr.GetString(0);
                        }
                        else if (dbVersion.Version.Major == 12)
                        {
                            dbVersion.ProductName += "2014 " + rdr.GetString(0);
                        }
                        else if (dbVersion.Version.Major == 11)
                        {
                            dbVersion.ProductName += "2012 " + rdr.GetString(0);
                        }
                        else if (dbVersion.Version.Major == 10)
                        {
                            if (dbVersion.Version.Minor >= 50)
                            {
                                dbVersion.ProductName += "2008 R2 " + rdr.GetString(0);
                            }
                            else
                            {
                                dbVersion.ProductName += "2008 " + rdr.GetString(0);
                            }
                        }
                        else if (dbVersion.Version.Major == 9)
                        {
                            dbVersion.ProductName += "2005 " + rdr.GetString(0);
                        }
                        else if (dbVersion.Version.Major == 8)
                        {
                            dbVersion.ProductName += "2000 " + rdr.GetString(0);
                        }
                        else if (dbVersion.Version.Major == 7)
                        {
                            dbVersion.ProductName += "7.0 " + rdr.GetString(0);
                        }

                        dbVersion.Is64Bit = dbVersion.Edition.ToLowerInvariant().Contains("64-bit");
                    }
                    rdr.Close();

                    return(dbVersion);
                }
            }
            catch
            {
                //ignore error
                return(null);
            }
            finally
            {
                if (!isConOpen && connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
        }
Beispiel #4
0
        public override DBVersionInfo FetchDBServerInfo(IDbConnection connection)
        {
            if (connection == null)
            {
                throw new Exception("Required valid connection object to initialise database details");
            }

            string query     = @"SELECT version();";
            bool   isConOpen = connection.State == ConnectionState.Open;

            try
            {
                if (!isConOpen)
                {
                    connection.Open();
                }

                IDbCommand cmd = connection.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = query;

                DBVersionInfo dbVersion = new DBVersionInfo();

                using (IDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        string   strVersion   = rdr.GetString(0);
                        string[] versionParts = strVersion.Split(',');

                        if (versionParts.Length > 0)
                        {
                            dbVersion.ProductName = versionParts[0];

                            if (versionParts[versionParts.Length - 1].ToLowerInvariant().Trim().Contains("64-bit"))
                            {
                                dbVersion.Is64Bit = true;
                            }
                        }
                    }

                    rdr.Close();
                }

                cmd.CommandText = "SHOW server_version;";
                using (IDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        dbVersion.Version = new Version(rdr.GetString(0));
                    }
                    rdr.Close();
                }

                return(dbVersion);
            }
            catch
            {
                //ignore error
                return(null);
            }
            finally
            {
                if (!isConOpen && connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
        }