Пример #1
0
 public override IDbConnection GetIDbConnection(IConnectionInfo cxInfo)
 {
     using (var conn = new LINQPadDataConnection(cxInfo))
     {
         return(conn.DataProvider.CreateConnection(conn.ConnectionString));
     }
 }
Пример #2
0
 public static void ClearConnectionPools(IConnectionInfo cxInfo)
 {
     using var db = new LINQPadDataConnection(cxInfo);
     if (db.Connection is SqlConnection connection)
     {
         SqlConnection.ClearPool(connection);
     }
 }
Пример #3
0
 public override void ClearConnectionPools(IConnectionInfo cxInfo)
 {
     using (var db = new LINQPadDataConnection(cxInfo))
         if (db.Connection is SqlConnection connection)
         {
             SqlConnection.ClearPool(connection);
         }
 }
 public override void ClearConnectionPools(IConnectionInfo cxInfo)
 {
     using (var db = new LINQPadDataConnection(cxInfo))
     {
         var connection = db.Connection as SqlConnection;
         if (connection != null)
         {
             SqlConnection.ClearPool(connection);
         }
     }
 }
        public override DateTime?GetLastSchemaUpdate(IConnectionInfo cxInfo)
        {
            var providerName = (string)cxInfo.DriverData.Element("providerName");

            if (providerName == ProviderName.SqlServer)
            {
                using (var db = new LINQPadDataConnection(cxInfo))
                    return(db.Query <DateTime?>("select max(modify_date) from sys.objects").FirstOrDefault());
            }

            return(null);
        }
Пример #6
0
        public static bool ShowConnectionDialog(DataContextDriver driver, IConnectionInfo cxInfo, bool isNewConnection, bool isDynamic)
        {
            var model        = new ConnectionViewModel();
            var providerName = isNewConnection
                                ? ProviderName.SqlServer
                                : (string)cxInfo.DriverData.Element("providerName");

            if (providerName != null)
            {
                model.SelectedProvider = model.Providers.FirstOrDefault(p => p.Name == providerName);
            }

            model.Name                    = cxInfo.DisplayName;
            model.IsDynamic               = isDynamic;
            model.CustomAssemblyPath      = cxInfo.CustomTypeInfo.CustomAssemblyPath;
            model.CustomTypeName          = cxInfo.CustomTypeInfo.CustomTypeName;
            model.AppConfigPath           = cxInfo.AppConfigPath;
            model.CustomConfiguration     = cxInfo.DriverData.Element("customConfiguration")?.Value;
            model.Persist                 = cxInfo.Persist;
            model.IsProduction            = cxInfo.IsProduction;
            model.EncryptConnectionString = cxInfo.DatabaseInfo.EncryptCustomCxString;
            model.Pluralize               = !cxInfo.DynamicSchemaOptions.NoPluralization;
            model.Capitalize              = !cxInfo.DynamicSchemaOptions.NoCapitalization;
            model.IncludeRoutines         = !cxInfo.DynamicSchemaOptions.ExcludeRoutines;
            model.ConnectionString        = cxInfo.DatabaseInfo.CustomCxString.IsNullOrWhiteSpace() ? (string)cxInfo.DriverData.Element("connectionString") : cxInfo.DatabaseInfo.CustomCxString;
            model.IncludeSchemas          = cxInfo.DriverData.Element("includeSchemas")?.Value;
            model.ExcludeSchemas          = cxInfo.DriverData.Element("excludeSchemas")?.Value;
            model.IncludeCatalogs         = cxInfo.DriverData.Element("includeCatalogs")?.Value;
            model.ExcludeCatalogs         = cxInfo.DriverData.Element("excludeCatalogs")?.Value;
            //model.NormalizeNames           = cxInfo.DriverData.Element("normalizeNames")          ?.Value.ToLower() == "true";
            model.AllowMultipleQuery       = cxInfo.DriverData.Element("allowMultipleQuery")?.Value.ToLower() == "true";
            model.UseProviderSpecificTypes = cxInfo.DriverData.Element("useProviderSpecificTypes")?.Value.ToLower() == "true";
            model.UseCustomFormatter       = cxInfo.DriverData.Element("useCustomFormatter")?.Value.ToLower() == "true";
            model.CommandTimeout           = cxInfo.DriverData.ElementValueOrDefault("commandTimeout", str => str.ToInt32() ?? 0, 0);

            model.OptimizeJoins = cxInfo.DriverData.Element("optimizeJoins") == null || cxInfo.DriverData.Element("optimizeJoins")?.Value.ToLower() == "true";

            if (ConnectionDialog.Show(model, isDynamic ? (Func <ConnectionViewModel, Exception>)TestConnection : null))
            {
                providerName = model.SelectedProvider?.Name;

                cxInfo.DriverData.SetElementValue("providerName", providerName);
                cxInfo.DriverData.SetElementValue("connectionString", null);
                cxInfo.DriverData.SetElementValue("includeSchemas", model.IncludeSchemas.IsNullOrWhiteSpace() ? null : model.IncludeSchemas);
                cxInfo.DriverData.SetElementValue("excludeSchemas", model.ExcludeSchemas.IsNullOrWhiteSpace() ? null : model.ExcludeSchemas);
                cxInfo.DriverData.SetElementValue("includeCatalogs", model.IncludeCatalogs.IsNullOrWhiteSpace() ? null : model.IncludeSchemas);
                cxInfo.DriverData.SetElementValue("excludeCatalogs", model.ExcludeCatalogs.IsNullOrWhiteSpace() ? null : model.ExcludeSchemas);
                cxInfo.DriverData.SetElementValue("optimizeJoins", model.OptimizeJoins            ? "true" : "false");
                cxInfo.DriverData.SetElementValue("allowMultipleQuery", model.AllowMultipleQuery       ? "true" : "false");
                //cxInfo.DriverData.SetElementValue("normalizeNames",           model.NormalizeNames           ? "true" : null);
                cxInfo.DriverData.SetElementValue("useProviderSpecificTypes", model.UseProviderSpecificTypes ? "true" : null);
                cxInfo.DriverData.SetElementValue("useCustomFormatter", model.UseCustomFormatter       ? "true" : null);
                cxInfo.DriverData.SetElementValue("commandTimeout", model.CommandTimeout.ToString());

                switch (providerName)
                {
                case ProviderName.Access: cxInfo.DatabaseInfo.Provider = typeof(AccessType).Namespace; break;

                case ProviderName.DB2:
                case ProviderName.DB2LUW:
                case ProviderName.DB2zOS: cxInfo.DatabaseInfo.Provider = typeof(DB2Type).Namespace; break;

                case ProviderName.Informix: cxInfo.DatabaseInfo.Provider = typeof(InformixType).Namespace; break;

                case ProviderName.Firebird: cxInfo.DatabaseInfo.Provider = typeof(FirebirdType).Namespace; break;

                case ProviderName.PostgreSQL: cxInfo.DatabaseInfo.Provider = typeof(PostgreSQLType).Namespace; break;

                case ProviderName.OracleNative: cxInfo.DatabaseInfo.Provider = typeof(OracleNativeType).Namespace; break;

                case ProviderName.OracleManaged: cxInfo.DatabaseInfo.Provider = typeof(OracleManagedType).Namespace; break;

                case ProviderName.MySql: cxInfo.DatabaseInfo.Provider = typeof(MySqlType).Namespace; break;

                case ProviderName.SqlCe: cxInfo.DatabaseInfo.Provider = typeof(SqlCeType).Namespace; break;

                case ProviderName.SQLite: cxInfo.DatabaseInfo.Provider = typeof(SQLiteType).Namespace; break;

                case ProviderName.SqlServer: cxInfo.DatabaseInfo.Provider = typeof(SqlServerType).Namespace; break;

                case ProviderName.Sybase: cxInfo.DatabaseInfo.Provider = typeof(SybaseType).Namespace; break;

                case ProviderName.SapHana: cxInfo.DatabaseInfo.Provider = typeof(SapHanaType).Namespace; break;
                }

                string providerVersion = null;

                try
                {
                    using (var db = new LINQPadDataConnection(providerName, model.ConnectionString))
                    {
                        db.CommandTimeout = model.CommandTimeout;

                        cxInfo.DatabaseInfo.Provider  = db.Connection.GetType().Namespace;
                        cxInfo.DatabaseInfo.Server    = ((DbConnection)db.Connection).DataSource;
                        cxInfo.DatabaseInfo.Database  = db.Connection.Database;
                        cxInfo.DatabaseInfo.DbVersion = ((DbConnection)db.Connection).ServerVersion;

                        if (providerName == ProviderName.SqlServer)
                        {
                            int version;

                            if (int.TryParse(cxInfo.DatabaseInfo.DbVersion?.Split('.')[0], out version))
                            {
                                switch (version)
                                {
                                case  8: providerVersion = ProviderName.SqlServer2000; break;

                                case  9: providerVersion = ProviderName.SqlServer2005; break;

                                case 10: providerVersion = ProviderName.SqlServer2008; break;

                                case 11: providerVersion = ProviderName.SqlServer2012; break;

                                case 12: providerVersion = ProviderName.SqlServer2014; break;

                                default:
                                    if (version > 12)
                                    {
                                        providerVersion = ProviderName.SqlServer2014;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                catch
                {
                }

                cxInfo.DriverData.SetElementValue("providerVersion", providerVersion);
                cxInfo.DriverData.SetElementValue("customConfiguration", model.CustomConfiguration.IsNullOrWhiteSpace() ? null : model.CustomConfiguration);

                cxInfo.CustomTypeInfo.CustomAssemblyPath = model.CustomAssemblyPath;
                cxInfo.CustomTypeInfo.CustomTypeName     = model.CustomTypeName;
                cxInfo.AppConfigPath = model.AppConfigPath;
                cxInfo.DatabaseInfo.CustomCxString           = model.ConnectionString;
                cxInfo.DatabaseInfo.EncryptCustomCxString    = model.EncryptConnectionString;
                cxInfo.DynamicSchemaOptions.NoPluralization  = !model.Pluralize;
                cxInfo.DynamicSchemaOptions.NoCapitalization = !model.Capitalize;
                cxInfo.DynamicSchemaOptions.ExcludeRoutines  = !model.IncludeRoutines;
                cxInfo.Persist      = model.Persist;
                cxInfo.IsProduction = model.IsProduction;
                cxInfo.DisplayName  = model.Name.IsNullOrWhiteSpace() ? null : model.Name;

                return(true);
            }

            return(false);
        }