示例#1
0
        public static MySqlConnectionSettings GetSettings(DbConnection connection, MySqlRetryNoDependendiciesExecutionStrategy mySqlRetryNoDependendiciesExecutionStrategy)
        {
            var csb         = new MySqlConnectionStringBuilder(connection.ConnectionString);
            var settingsCsb = _settingsCsb(csb);

            return(Settings.GetOrAdd(settingsCsb.ConnectionString, key =>
            {
                var opened = false;
                if (connection.State == ConnectionState.Closed)
                {
                    mySqlRetryNoDependendiciesExecutionStrategy.Execute(() =>
                    {
                        connection.Open();
                    });
                    opened = true;
                }
                try
                {
                    var version = new ServerVersion(connection.ServerVersion);
                    var connectionSettings = new MySqlConnectionSettings(settingsCsb, version);
                    return connectionSettings;
                }
                finally
                {
                    if (opened)
                    {
                        connection.Close();
                    }
                }
            }));
        }
示例#2
0
        public static MySqlConnectionSettings GetSettings(string connectionString, MySqlRetryNoDependendiciesExecutionStrategy mySqlRetryNoDependendiciesExecutionStrategy)
        {
            var csb         = new MySqlConnectionStringBuilder(connectionString);
            var settingsCsb = _settingsCsb(csb);

            return(Settings.GetOrAdd(settingsCsb.ConnectionString, key =>
            {
                csb.Database = "";
                csb.Pooling = false;
                string serverVersion = "";

                mySqlRetryNoDependendiciesExecutionStrategy.Execute(() =>
                {
                    using (var schemalessConnection = new MySqlConnection(csb.ConnectionString))
                    {
                        schemalessConnection.Open();
                        serverVersion = schemalessConnection.ServerVersion;
                    }
                });

                var version = new ServerVersion(serverVersion);
                return new MySqlConnectionSettings(settingsCsb, version);
            }));
        }