示例#1
0
        private static IDataProvider ProviderDetector(IConnectionStringSettings css, string connectionString)
        {
            if (css.IsGlobal)
            {
                return(null);
            }
            if (css.Name == DB2iSeriesFactory.ProviderName || new[] { DB2iSeriesFactory.ProviderName, AssemblyName }.Contains(css.ProviderName))
            {
                if (AutoDetectProvider)
                {
                    try
                    {
                        var connectionType    = Type.GetType(ConnectionTypeName, true);
                        var connectionCreator = DynamicDataProviderBase.CreateConnectionExpression(connectionType).Compile();
                        var cs = string.IsNullOrWhiteSpace(connectionString) ? css.ConnectionString : connectionString;

                        using (var conn = connectionCreator(cs))
                        {
                            conn.Open();
                            return(_db2iSeriesDataProvider);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(null);
        }
示例#2
0
        static IDataProvider ProviderDetector(ConnectionStringSettings css)
        {
            if (css.ElementInformation.Source == null ||
                css.ElementInformation.Source.EndsWith("machine.config", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            switch (css.ProviderName)
            {
            case "":
            case null:

                if (css.Name == "DB2")
                {
                    goto case "DB2";
                }
                break;

            case "DB2":
            case "IBM.Data.DB2":

                if (css.Name.Contains("LUW") || css.Name.Contains("z/OS") || css.Name.Contains("zOS"))
                {
                    break;
                }

                if (AutoDetectProvider)
                {
                    try
                    {
                        var connectionType = Type.GetType("IBM.Data.DB2.DB2Connection, IBM.Data.DB2", true);
                        var serverTypeProp = connectionType
                                             .GetProperties(BindingFlags.NonPublic | BindingFlags.Instance)
                                             .FirstOrDefault(p => p.Name == "eServerType");

                        if (serverTypeProp != null)
                        {
                            var connectionCreator = DynamicDataProviderBase.CreateConnectionExpression(connectionType).Compile();

                            using (var conn = connectionCreator(css.ConnectionString))
                            {
                                conn.Open();

                                var serverType = Expression.Lambda <Func <object> >(
                                    Expression.Convert(
                                        Expression.MakeMemberAccess(Expression.Constant(conn), serverTypeProp),
                                        typeof(object)))
                                                 .Compile()();

                                var iszOS = serverType.ToString() == "DB2_390";

                                return(iszOS ? _db2DataProviderzOS : _db2DataProviderLUW);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                break;
            }

            return(null);
        }
示例#3
0
        static IDataProvider ProviderDetector(IConnectionStringSettings css, string connectionString)
        {
            //if (css.IsGlobal /* DataConnection.IsMachineConfig(css)*/)
            //	return null;

            switch (css.ProviderName)
            {
            case "":
            case null:

                if (css.Name == "PostgreSQL")
                {
                    goto case "PostgreSQL";
                }
                break;

            case "PostgreSQL92":
            case "PostgreSQL.92":
            case "PostgreSQL.9.2":
                return(_postgreSQLDataProvider);

            case "PostgreSQL93":
            case "PostgreSQL.93":
            case "PostgreSQL.9.3":
            case "PostgreSQL94":
            case "PostgreSQL.94":
            case "PostgreSQL.9.4":
                return(_postgreSQLDataProvider93);

            case "PostgreSQL95":
            case "PostgreSQL.95":
            case "PostgreSQL.9.5":
            case "PostgreSQL96":
            case "PostgreSQL.96":
            case "PostgreSQL.9.6":
                return(_postgreSQLDataProvider95);

            case "PostgreSQL":
            case "Npgsql":

                if (css.Name.Contains("92") || css.Name.Contains("9.2"))
                {
                    return(_postgreSQLDataProvider);
                }

                if (css.Name.Contains("93") || css.Name.Contains("9.3") ||
                    css.Name.Contains("94") || css.Name.Contains("9.4"))
                {
                    return(_postgreSQLDataProvider93);
                }

                if (css.Name.Contains("95") || css.Name.Contains("9.5") ||
                    css.Name.Contains("96") || css.Name.Contains("9.6"))
                {
                    return(_postgreSQLDataProvider95);
                }

                if (AutoDetectProvider)
                {
                    try
                    {
                        var connectionType    = Type.GetType("Npgsql.NpgsqlConnection, Npgsql", true);
                        var connectionCreator = DynamicDataProviderBase.CreateConnectionExpression(connectionType).Compile();
                        var cs = string.IsNullOrWhiteSpace(connectionString) ? css.ConnectionString : connectionString;

                        using (var conn = connectionCreator(cs))
                        {
                            conn.Open();

                            var postgreSqlVersion = ((dynamic)conn).PostgreSqlVersion;

                            if (postgreSqlVersion.Major > 9 || postgreSqlVersion.Major == 9 && postgreSqlVersion.Minor > 4)
                            {
                                return(_postgreSQLDataProvider95);
                            }

                            if (postgreSqlVersion.Major == 9 && postgreSqlVersion.Minor > 2)
                            {
                                return(_postgreSQLDataProvider93);
                            }

                            return(_postgreSQLDataProvider);
                        }
                    }
                    catch (Exception)
                    {
                        return(_postgreSQLDataProvider);
                    }
                }

                break;
            }

            return(null);
        }
示例#4
0
        static IDataProvider ProviderDetector(IConnectionStringSettings css, string connectionString)
        {
            //if (css.IsGlobal /* DataConnection.IsMachineConfig(css)*/)
            //	return null;

            switch (css.ProviderName)
            {
            case "":
            case null:

                if (css.Name == "DB2")
                {
                    goto case "DB2";
                }
                break;

            case "IBM.Data.DB2.Core":
                IsCore       = true;
                AssemblyName = "IBM.Data.DB2.Core";

                goto case "DB2";

            case "DB2":
            case "IBM.Data.DB2":

                if (css.Name.Contains("LUW") || css.Name.Contains("z/OS") || css.Name.Contains("zOS"))
                {
                    break;
                }

                if (AutoDetectProvider)
                {
                    try
                    {
                        var connectionType = Type.GetType(AssemblyName + ".DB2Connection, " + AssemblyName, true);
                        var serverTypeProp = connectionType
                                             .GetPropertiesEx(BindingFlags.NonPublic | BindingFlags.Instance)
                                             .FirstOrDefault(p => p.Name == "eServerType");

                        if (serverTypeProp != null)
                        {
                            var connectionCreator = DynamicDataProviderBase.CreateConnectionExpression(connectionType).Compile();
                            var cs = string.IsNullOrWhiteSpace(connectionString) ? css.ConnectionString : connectionString;

                            using (var conn = connectionCreator(cs))
                            {
                                conn.Open();

                                var serverType = Expression.Lambda <Func <object> >(
                                    Expression.Convert(
                                        Expression.MakeMemberAccess(Expression.Constant(conn), serverTypeProp),
                                        typeof(object)))
                                                 .Compile()();

                                var iszOS = serverType.ToString() == "DB2_390";

                                return(iszOS ? _db2DataProviderzOS : _db2DataProviderLUW);
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                break;
            }

            return(null);
        }
示例#5
0
        private static IDataProvider ProviderDetector(IConnectionStringSettings css, string connectionString)
        {
            if (css.IsGlobal)
            {
                return(null);
            }


            if (DB2iSeriesProviderName.AllNames.Contains(css.Name) || new[] { DB2iSeriesProviderName.DB2, AssemblyName }.Contains(css.ProviderName))
            {
                switch (css.Name)
                {
                case DB2iSeriesProviderName.DB2_73: return(_db2iDataProvider_73);

                case DB2iSeriesProviderName.DB2_GAS: return(_db2iDataProvider_gas);

                case DB2iSeriesProviderName.DB2_73_GAS: return(_db2iDataProvider_73_gas);
                }

                if (AutoDetectProvider)
                {
                    try
                    {
                        var connectionType    = Type.GetType(ConnectionTypeName, true);
                        var serverVersionProp = connectionType
                                                .GetPropertiesEx(BindingFlags.Public | BindingFlags.Instance)
                                                .FirstOrDefault(p => p.Name == "ServerVersion");

                        if (serverVersionProp != null)
                        {
                            var connectionCreator = DynamicDataProviderBase.CreateConnectionExpression(connectionType).Compile();
                            var cs = string.IsNullOrWhiteSpace(connectionString) ? css.ConnectionString : connectionString;

                            using (var conn = connectionCreator(cs))
                            {
                                conn.Open();

                                var version = Expression.Lambda <Func <object> >(
                                    Expression.Convert(
                                        Expression.MakeMemberAccess(Expression.Constant(conn), serverVersionProp),
                                        typeof(object)))
                                              .Compile()();

                                var serverVersion = version.ToString().Substring(0, 5);

                                string ptf;
                                int    desiredLevel;

                                switch (serverVersion)
                                {
                                case "07.03":
                                    return(_db2iDataProvider_73);

                                case "07.02":
                                    ptf          = "SF99702";
                                    desiredLevel = 9;
                                    break;

                                case "07.01":
                                    ptf          = "SF99701";
                                    desiredLevel = 38;
                                    break;

                                default:
                                    return(_db2iDataProvider);
                                }

                                using (var cmd = conn.CreateCommand())
                                {
                                    cmd.CommandText =
                                        "SELECT MAX(PTF_GROUP_LEVEL) FROM QSYS2.GROUP_PTF_INFO WHERE PTF_GROUP_NAME = @p1 AND PTF_GROUP_STATUS = 'INSTALLED'";
                                    var param = cmd.CreateParameter();
                                    param.ParameterName = "p1";
                                    param.Value         = ptf;

                                    cmd.Parameters.Add(param);

                                    var level = Converter.ChangeTypeTo <int>(cmd.ExecuteScalar());

                                    return(level < desiredLevel ? _db2iDataProvider : _db2iDataProvider_73);
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(null);
        }
        static IDataProvider ProviderDetector(ConnectionStringSettings css)
        {
            if (DataConnection.IsMachineConfig(css))
            {
                return(null);
            }

            switch (css.ProviderName)
            {
            case "":
            case null:

                if (css.Name == "PostgreSQL")
                {
                    goto case "PostgreSQL";
                }
                break;

            case "PostgreSQL92":
            case "PostgreSQL.92":
            case "PostgreSQL.9.2":
                return(_postgreSQLDataProvider);

            case "PostgreSQL93":
            case "PostgreSQL.93":
            case "PostgreSQL.9.3":
            case "PostgreSQL94":
            case "PostgreSQL.94":
            case "PostgreSQL.9.4":
            case "PostgreSQL95":
            case "PostgreSQL.95":
            case "PostgreSQL.9.5":
                return(_postgreSQLDataProvider93);

            case "PostgreSQL":
            case "Npgsql":

                if (css.Name.Contains("92") || css.Name.Contains("9.2"))
                {
                    return(_postgreSQLDataProvider);
                }

                if (css.Name.Contains("93") || css.Name.Contains("9.3") ||
                    css.Name.Contains("94") || css.Name.Contains("9.4") ||
                    css.Name.Contains("95") || css.Name.Contains("9.5"))
                {
                    return(_postgreSQLDataProvider93);
                }

                if (AutoDetectProvider)
                {
                    try
                    {
                        var connectionType    = Type.GetType("Npgsql.NpgsqlConnection, Npgsql", true);
                        var connectionCreator = DynamicDataProviderBase.CreateConnectionExpression(connectionType).Compile();

                        using (var conn = connectionCreator(css.ConnectionString))
                        {
                            conn.Open();

                            var postgreSqlVersion = ((dynamic)conn).PostgreSqlVersion;

                            return(postgreSqlVersion.Major > 9 || postgreSqlVersion.Major == 9 && postgreSqlVersion.Minor > 2
                                                                        ? _postgreSQLDataProvider93 : _postgreSQLDataProvider);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                break;
            }

            return(null);
        }