Exemplo n.º 1
0
        internal static string BuildConnectionString(MySqlConfiguration config, ref string server, string user, string password, ConnectFlags flags, int connectiontimeout = 0, string characterset = null)
        {
            // connection strings:
            if (server == null && user == null && password == null && flags == ConnectFlags.None && !string.IsNullOrEmpty(config.ConnectionString))
            {
                return(config.ConnectionString);
            }

            // TODO: local.ConnectionStringName

            // build connection string:
            string pipe_name = null;
            int    port      = -1;

            if (server != null)
            {
                ParseServerName(ref server, out port, out pipe_name);
            }
            else
            {
                server = config.Server;
            }

            if (port == -1)
            {
                port = config.Port;
            }
            if (user == null)
            {
                user = config.User;
            }
            if (password == null)
            {
                password = config.Password;
            }

            // build the connection string to be used with MySQL Connector/.NET
            // see http://dev.mysql.com/doc/refman/5.5/en/connector-net-connection-options.html
            return(BuildConnectionString(
                       server, user, password,
                       string.Format("allowzerodatetime=true;allow user variables=true;connect timeout={0};Port={1};SSL Mode={2};Use Compression={3}{4}{5};Max Pool Size={6}{7}{8}",
                                     (connectiontimeout > 0) ? connectiontimeout : (config.ConnectTimeout > 0) ? config.ConnectTimeout : 15,
                                     port,
                                     (flags & ConnectFlags.SSL) != 0 ? "Preferred" : "None",               // (since Connector 6.2.1.) ssl mode={None|Preferred|Required|VerifyCA|VerifyFull}   // (Jakub) use ssl={true|false} has been deprecated
                                     (flags & ConnectFlags.Compress) != 0 ? "true" : "false",              // Use Compression={true|false}
                                     (pipe_name != null) ? ";Pipe=" + pipe_name : null,                    // Pipe={...}
                                     (flags & ConnectFlags.Interactive) != 0 ? ";Interactive=true" : null, // Interactive={true|false}
                                     config.MaxPoolSize,                                                   // Max Pool Size=100
                                     (config.DefaultCommandTimeout >= 0) ? ";DefaultCommandTimeout=" + config.DefaultCommandTimeout : null,
                                     string.IsNullOrEmpty(characterset) ? null : ";characterset=" + characterset
                                     )
                       ));
        }
Exemplo n.º 2
0
 public Registrator()
 {
     Context.RegisterConfiguration(new MySqlConfiguration());
     MySqlConfiguration.RegisterLegacyOptions();
 }
Exemplo n.º 3
0
        internal static MySqlConnectionStringBuilder BuildConnectionString(MySqlConfiguration config, ref string server, int defaultport = 3306, string user = null, string password = null, ConnectFlags flags = ConnectFlags.None)
        {
            // build connection string:
            string pipe_name = null;
            int    port      = -1;

            if (server != null)
            {
                ParseServerName(ref server, out port, out pipe_name);
            }
            else
            {
                server = config.Server;
            }

            if (port == -1)
            {
                port = defaultport > 0 ? defaultport : config.Port;
            }
            if (user == null)
            {
                user = config.User;
            }
            if (password == null)
            {
                password = config.Password;
            }

            //
            var builder = new MySqlConnectionStringBuilder()
            {
                Server   = server,
                UserID   = user,
                Password = password,
                //Database = dbname,
                AllowZeroDateTime       = true,
                AllowUserVariables      = true,
                AllowPublicKeyRetrieval = true,
                Port            = (uint)port,
                SslMode         = (flags & ConnectFlags.SSL) != 0 ? MySqlSslMode.Preferred : MySqlSslMode.None,
                UseCompression  = (flags & ConnectFlags.Compress) != 0,
                MaximumPoolSize = (uint)config.MaxPoolSize,
                Pooling         = (flags & ConnectFlags.Pooling) != 0,
            };

            // optional:
            if (pipe_name != null)
            {
                builder.PipeName = pipe_name;
            }
            if ((flags & ConnectFlags.Interactive) != 0)
            {
                builder.InteractiveSession = true;
            }
            if (config.ConnectTimeout > 0)
            {
                builder.ConnectionTimeout = (uint)config.ConnectTimeout;
            }
            if (config.DefaultCommandTimeout >= 0)
            {
                builder.DefaultCommandTimeout = (uint)config.DefaultCommandTimeout;
            }

            //
            return(builder);
        }