public void TestConnectingSocketBadHostName()
        {
            MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder(Connection.ConnectionString);

            connStr.Server = "foobar";
            MySqlConnection c  = new MySqlConnection(connStr.GetConnectionString(true));
            var             ex = Assert.Throws <MySqlException>(() => c.Open());

            Assert.AreEqual((int)MySqlErrorCode.UnableToConnectToHost, ex.Number);
        }
        public void Keepalive()
        {
            MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder(Connection.ConnectionString);

            connStr.Keepalive = 1;
            using (MySqlConnection c = new MySqlConnection(connStr.GetConnectionString(true)))
            {
                c.Open();
            }
        }
Example #3
0
 public MySqlManager(ILogger log, MySqlConnectionStringBuilder masterConnectionString)
 {
     this.log = log;
     MasterConnectionString = new MySqlConnectionStringBuilder(masterConnectionString.GetConnectionString(true))
     {
         Database = null
     };
     MySqlDumpPath = "mysqldump";
     MySqlPath     = "mysql";
 }
        public void Setup(TestBase testClass, bool reinitDatabase = false)
        {
            if (!String.IsNullOrEmpty(Namespace) && !reinitDatabase)
            {
                return;
            }

            Debug.Assert(testClass != null);

            TestClass = testClass;
            Namespace = testClass.GetType().Name.ToLower();
            string ns = Namespace.Length > 10 ? Namespace.Substring(0, 10) : Namespace;

            BaseDBName   = "db-" + ns + "-";
            BaseUserName = "******" + ns + "-";

            var settings = new MySqlConnectionStringBuilder();

            settings.Server = "localhost";
            var port = Environment.GetEnvironmentVariable("MYSQL_PORT");

            settings.Port     = port == null ? 3306 : UInt32.Parse(port);
            settings.UserID   = "root";
            settings.Password = null;
#if !(NETCOREAPP1_1 || NETCOREAPP2_2)
            var memName = Environment.GetEnvironmentVariable("MYSQL_MEM");
            settings.SharedMemoryName = memName == null ? "MySQLSocket" : memName;
            var pipeName = Environment.GetEnvironmentVariable("MYSQL_PIPE");
            settings.PipeName = pipeName == null ? "MySQLSocket" : pipeName;
#endif
            settings.PersistSecurityInfo = true;
            settings.AllowUserVariables  = true;
            settings.Pooling             = false;
            settings.IgnorePrepare       = false;
            settings.ConnectionTimeout   = 600;
            TestClass.AdjustConnectionSettings(settings);
            MaxPacketSize = 1000 * 1024;

            RootSettings = new MySqlConnectionStringBuilder(settings.GetConnectionString(true));
            Settings     = new MySqlConnectionStringBuilder(settings.GetConnectionString(true));
            Version      = GetVersion();
            InitializeDatabase();
        }
Example #5
0
        public MySQL(MySQLConnectData connectData)
        {
            MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();

            builder.Server   = connectData.Server;
            builder.Port     = connectData.Port;
            builder.UserID   = connectData.UserID;
            builder.Password = connectData.Password;
            builder.Database = connectData.DataBase;
            _connection      = new MySqlConnection(builder.GetConnectionString(true));
        }
Example #6
0
        private MySqlConnection GetConnection()
        {
            var builder = new MySqlConnectionStringBuilder();

            builder.Server   = serverAddress;
            builder.Port     = 4309;
            builder.Database = "shorewarecdr";
            builder.UserID   = "st_cdrupdate";
            builder.Password = "******";
            return(new MySqlConnection(builder.GetConnectionString(true)));
        }
Example #7
0
        internal static String getConnectionString()
        {
            var Builder = new MySqlConnectionStringBuilder();

            Builder.Server   = oBEUMySQL.ServerName;
            Builder.Port     = oBEUMySQL.Port;
            Builder.UserID   = oBEUMySQL.Username;
            Builder.Password = oBEUMySQL.Password;
            Builder.SslMode  = MySqlSslMode.None;
            return(Builder.GetConnectionString(true));
        }
Example #8
0
        /// <summary>
        /// Creates a new MySqlConnection object with the exact same ConnectionString value
        /// </summary>
        /// <returns>A cloned MySqlConnection object</returns>
        object ICloneable.Clone()
        {
            MySqlConnection clone            = new MySqlConnection();
            string          connectionString = settings.GetConnectionString(true);

            if (connectionString != null)
            {
                clone.ConnectionString = connectionString;
            }
            return(clone);
        }
 public DB_Connect()
 {
     builder               = new MySqlConnectionStringBuilder();
     conn                  = new MySqlConnection();
     builder.Database      = "mscDB"; // Сюда надо записать правильные значения потом
     builder.UserID        = "root";
     builder.Password      = "";
     builder.Server        = "localhost";
     conn.ConnectionString = builder.GetConnectionString(true);
     conn.Open();
 }
 public MyCatRelationalConnection CreateMasterConnection()
 {
     var csb = new MySqlConnectionStringBuilder(ConnectionString) {
         Database = "MyCat",
         Pooling = false
     };
     
     var optionsBuilder = new DbContextOptionsBuilder();
     optionsBuilder.UseMyCat(csb.GetConnectionString(true));
     return new MyCatRelationalConnection(optionsBuilder.Options, Logger);
 }
        public void TestConnectingSocketBadDbName()
        {
            MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder(Connection.ConnectionString);

            connStr.Password = "******";
            MySqlConnection c         = new MySqlConnection(connStr.GetConnectionString(true));
            var             exception = Record.Exception(() => c.Open());

            Assert.NotNull(exception);
            Assert.IsType <MySqlException>(exception);
        }
Example #12
0
        protected static void CreateConnection(string server, string bd, string login, string pass)
        {
            MySqlConnectionStringBuilder sb = new MySqlConnectionStringBuilder();

            sb.Server       = "localhost";
            sb.Database     = "taximanager_db";
            sb.UserID       = "root";
            sb.Password     = "******";
            sb.CharacterSet = "utf8";
            connection      = new MySqlConnection(sb.GetConnectionString(true));
        }
Example #13
0
        // Save button clicked
        private void btn_save_Click(object sender, EventArgs e)
        {
            // Save the new values
            MySqlConnectionStringBuilder builder_p = new MySqlConnectionStringBuilder();

            builder_p.Server = tb_server_p.Text.Trim();
            if (!String.IsNullOrWhiteSpace(tb_port_p.Text))
            {
                builder_p.Port = uint.Parse(tb_port_p.Text);
            }
            else
            {
                builder_p.Port = defaultPort;
            }
            builder_p.Database = tb_dbname_p.Text.Trim();
            builder_p.UserID   = tb_username_p.Text.Trim();
            builder_p.Password = tb_password_p.Text.Trim();

            MySqlConnectionStringBuilder builder_b = new MySqlConnectionStringBuilder();

            builder_b.Server = tb_server_b.Text.Trim();
            if (!String.IsNullOrWhiteSpace(tb_port_b.Text))
            {
                builder_b.Port = uint.Parse(tb_port_b.Text);
            }
            else
            {
                builder_b.Port = defaultPort;
            }
            builder_b.Database = tb_dbname_b.Text.Trim();
            builder_b.UserID   = tb_username_b.Text.Trim();
            builder_b.Password = tb_password_b.Text.Trim();

            Exception ex_p;
            Exception ex_b;

            if (validateConnection(builder_p, out ex_p))
            {
                if (validateConnection(builder_b, out ex_b))
                {
                    save(builder_p.GetConnectionString(true), builder_b.GetConnectionString(true));
                    this.Close();
                }
                else
                {
                    MessageBox.Show("There is a problem with the backup connection configuration!" + Environment.NewLine + "Please verify that the configuration entered is correct." + Environment.NewLine + Environment.NewLine + "(" + ex_b.Message + ")", "Backup Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("There is a problem with the primary connection configuration!" + Environment.NewLine + "Please verify that the configuration entered is correct." + Environment.NewLine + Environment.NewLine + "(" + ex_p.Message + ")", "Primary Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #14
0
        public void ConnectDb(string UserId, string Password, string Database = "world", string Hostname = "localhost")
        {
            var sql = new MySqlConnectionStringBuilder();

            sql.Password = Password;
            sql.Database = Database;
            sql.UserID   = UserId;
            sql.Server   = Hostname;
            var dbCon = new MySqlConnection(sql.GetConnectionString(true));

            Db = new TrinityDB(dbCon);
        }
Example #15
0
        public void InvalidCast()
        {
            executeSQL(String.Format("CREATE FUNCTION `{0}`.`MyTwice`( val int ) RETURNS INT BEGIN return val * 2; END;", Connection.Database), true);
            executeSQL(String.Format("CREATE PROCEDURE `{0}`.`spMyTwice`( out result int, val int ) BEGIN set result = val * 2; END;", Connection.Database), true);
            string user = Fixture.CreateUser("1", "123");

            executeSQL(String.Format("GRANT EXECUTE ON FUNCTION `{0}`.`MyTwice` TO '{1}'@'localhost';", Connection.Database, user), true);
            executeSQL(String.Format("GRANT EXECUTE ON PROCEDURE `{0}`.`spMyTwice` TO '{1}'@'localhost'", Connection.Database, user), true);

            if (Connection.driver.Version.isAtLeast(8, 0, 1))
            {
                executeSQL("GRANT SELECT ON TABLE mysql.db TO 'user1'@'localhost'", true);
            }
            else
            {
                executeSQL("GRANT SELECT ON TABLE mysql.proc TO 'user1'@'localhost'", true);
            }

            executeSQL("FLUSH PRIVILEGES", true);

            MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder(Connection.ConnectionString);

            connStr.UserID   = user;
            connStr.Password = "******";
            MySqlConnection con = new MySqlConnection(connStr.GetConnectionString(true));

            // Invoke the function
            var cmd = con.CreateCommand();

            using (con)
            {
                con.Open();
                cmd.CommandText = "MyTwice";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new MySqlParameter("val", System.DBNull.Value));
                cmd.Parameters.Add("@p", MySqlDbType.Int32);
                cmd.Parameters[1].Direction = ParameterDirection.ReturnValue;
                cmd.Parameters[0].Value     = 20;
                cmd.ExecuteNonQuery();
                Assert.Equal(cmd.Parameters[1].Value, 40);

                cmd.CommandText = "spMyTwice";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Clear();
                cmd.Parameters.Add(new MySqlParameter("result", System.DBNull.Value));
                cmd.Parameters.Add("val", MySqlDbType.Int32);
                cmd.Parameters[0].Direction = ParameterDirection.Output;
                cmd.Parameters[1].Value     = 20;
                cmd.ExecuteNonQuery();
                Assert.Equal(cmd.Parameters[0].Value, 40);
            }
        }
        public EmailStatusUpdateWorker(ILogger <EmailStatusUpdateWorker> logger, IConfiguration configuration, IModel channel, IEmailRepository emailRepository)
        {
            if (configuration is null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _logger          = logger ?? throw new ArgumentNullException(nameof(logger));
            _channel         = channel ?? throw new ArgumentNullException(nameof(channel));
            _emailRepository = emailRepository ?? throw new ArgumentNullException(nameof(emailRepository));
            _storedEmailStatusUpdatingQueueId = configuration.GetSection(_queuesConfigurationSection)
                                                .GetValue <string>(_emailStatusUpdateQueueParameter);
            _channel.QueueDeclare(_storedEmailStatusUpdatingQueueId, true, false, false, null);
            _consumer           = new AsyncEventingBasicConsumer(_channel);
            _consumer.Received += MessageRecieved;

            try
            {
                var conStrBuilder = new MySqlConnectionStringBuilder();

                var databaseSection = configuration.GetSection("Database");

                conStrBuilder.Server   = databaseSection.GetValue("Host", "localhost");
                conStrBuilder.Port     = databaseSection.GetValue <uint>("Port", 3306);
                conStrBuilder.UserID   = databaseSection.GetValue("Username", "");
                conStrBuilder.Password = databaseSection.GetValue("Password", "");
                conStrBuilder.Database = databaseSection.GetValue("DatabaseName", "");
                conStrBuilder.SslMode  = MySqlSslMode.None;

                QSMain.ConnectionString = conStrBuilder.GetConnectionString(true);
                var db_config = FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard
                                .Dialect <NHibernate.Spatial.Dialect.MySQL57SpatialDialect>()
                                .ConnectionString(QSMain.ConnectionString);

                OrmConfig.ConfigureOrm(db_config,
                                       new System.Reflection.Assembly[] {
                    System.Reflection.Assembly.GetAssembly(typeof(Vodovoz.HibernateMapping.OrganizationMap)),
                    System.Reflection.Assembly.GetAssembly(typeof(QS.Banks.Domain.Bank)),
                    System.Reflection.Assembly.GetAssembly(typeof(QS.HistoryLog.HistoryMain)),
                    System.Reflection.Assembly.GetAssembly(typeof(QS.Project.HibernateMapping.TypeOfEntityMap)),
                    System.Reflection.Assembly.GetAssembly(typeof(QS.Project.Domain.UserBase)),
                    System.Reflection.Assembly.GetAssembly(typeof(QS.Attachments.HibernateMapping.AttachmentMap))
                });

                QS.HistoryLog.HistoryMain.Enable();
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, "Ошибка чтения конфигурационного файла.");
                return;
            }
        }
        public MysqlWrapper(string a_host, string a_user, string a_password, string a_database)
        {
            //the class constructor

            //sets the values of the connection string to the values of the parameters of the constructor
            conString.Server   = a_host;
            conString.UserID   = a_user;
            conString.Password = a_password;
            conString.Database = a_database;

            //sets the value of the connection variable using the connectionstring (true indicates that the password has to be included)
            con = new MySqlConnection(conString.GetConnectionString(true));
        }
Example #18
0
        String CreateDatabaseConnectionString()
        {
            MySqlConnectionStringBuilder strBuilder = new MySqlConnectionStringBuilder();

            strBuilder.Database = DatabaseName;
            strBuilder.Server   = Host;
            strBuilder.UserID   = UserId;
            strBuilder.Password = Password;
            strBuilder.Pooling  = false;
            strBuilder.Port     = uint.Parse(Port);
            connectString       = strBuilder.GetConnectionString(true);
            return(connectString);
        }
Example #19
0
        private string GetConnectionString(string server, string uid, string pwd, string db, uint timeout)
        {
            MySqlConnectionStringBuilder connectionString = new MySqlConnectionStringBuilder();

            connectionString.Server            = server;
            connectionString.UserID            = uid;
            connectionString.Password          = pwd;
            connectionString.Database          = db;
            connectionString.ConnectionTimeout = timeout;
            //不使用连接池
            connectionString.Pooling = false;
            return(connectionString.GetConnectionString(true));
        }
Example #20
0
        public MySqlRelationalConnection CreateMasterConnection()
        {
            var csb = new MySqlConnectionStringBuilder(ConnectionString)
            {
                Database = "mysql",
                Pooling  = false
            };

            var optionsBuilder = new DbContextOptionsBuilder();

            optionsBuilder.UseMySql(csb.GetConnectionString(true));
            return(new MySqlRelationalConnection(optionsBuilder.Options, Logger));
        }
        public void create_basic_connectionString_with_IntegratedSecurity()
        {
            MySqlConnectionString mySqlConnectionStringExpected = new MySqlConnectionString()
            {
                Server             = "server",
                Database           = "database",
                IntegratedSecurity = true
            };
            MySqlConnectionString mySqlConnectionStringBuilder = new MySqlConnectionStringBuilder("server", "database");


            Assert.AreEqual(mySqlConnectionStringExpected.GetConnectionString(), mySqlConnectionStringBuilder.GetConnectionString());
        }
        public void TestPersistSecurityInfoCachingPasswords()
        {
            MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder(Connection.ConnectionString);

            // Persist Security Info = true means that it should be returned
            connStr.PersistSecurityInfo = true;
            MySqlConnection c = new MySqlConnection(connStr.GetConnectionString(true));

            c.Open();
            c.Close();
            MySqlConnectionStringBuilder afterOpenSettings = new MySqlConnectionStringBuilder(c.ConnectionString);

            Assert.AreEqual(connStr.Password, afterOpenSettings.Password);

            // Persist Security Info = false means that it should not be returned
            connStr.PersistSecurityInfo = false;
            c = new MySqlConnection(connStr.GetConnectionString(true));
            c.Open();
            c.Close();
            afterOpenSettings = new MySqlConnectionStringBuilder(c.ConnectionString);
            Assert.True(String.IsNullOrEmpty(afterOpenSettings.Password));
        }
Example #23
0
        public void DontAllowBatching()
        {
            MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder(Connection.ConnectionString);

            connStr.AllowBatch   = false;
            connStr.CharacterSet = "utf8";
            using (MySqlConnection c = new MySqlConnection(connStr.GetConnectionString(true)))
            {
                c.Open();
                MySqlCommand cmd = new MySqlCommand("SELECT 1", c);
                cmd.ExecuteScalar();
            }
        }
Example #24
0
        string GetMySqlConnectionString()
        {
            var csBuilder = new MySqlConnectionStringBuilder
            {
                Port     = 3306,
                Password = "******",
                UserID   = "root",
                Server   = "localhost",
                Database = "sys"
            };

            return(csBuilder.GetConnectionString(true));
        }
Example #25
0
        public static MySqlConnection GetConnection()
        {
            var connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Server   = SQL_Host;
            connBuilder.UserID   = SQL_User;
            connBuilder.Password = SQL_Password;
            connBuilder.Database = SQL_Database;
            connBuilder.Port     = SQL_Port;
            connBuilder.Pooling  = true;

            return(new MySqlConnection(connBuilder.GetConnectionString(true)));
        }
Example #26
0
        public void OneTimeSetUp()
        {
            Namespace = this.GetType().Name.ToLower();
            string ns = Namespace.Length > 10 ? Namespace.Substring(0, 10) : Namespace;

            BaseDBName   = "db-" + ns + "-";
            BaseUserName = "******" + ns + "-";

            var settings = new MySqlConnectionStringBuilder();

            settings.Server = "localhost";
            var port = Environment.GetEnvironmentVariable("MYSQL_PORT");

            settings.Port     = port == null ? 3306 : UInt32.Parse(port);
            settings.UserID   = "root";
            settings.Password = null;
#if NET452
            var memName = Environment.GetEnvironmentVariable("MYSQL_MEM");
            settings.SharedMemoryName = memName == null ? "MySQLSocket" : memName;
            var pipeName = Environment.GetEnvironmentVariable("MYSQL_PIPE");
            settings.PipeName = pipeName == null ? "MySQLSocket" : pipeName;
#endif
            settings.PersistSecurityInfo = true;
            settings.AllowUserVariables  = true;
            settings.Pooling             = false;
            settings.ConnectionTimeout   = 600;
            AdjustConnectionSettings(settings);
            MaxPacketSize = 1000 * 1024;

            RootSettings = new MySqlConnectionStringBuilder(settings.GetConnectionString(true));
            Settings     = new MySqlConnectionStringBuilder(settings.GetConnectionString(true));
            Version      = GetVersion();
            Debug.Assert(!string.IsNullOrEmpty(BaseDBName));
            InitializeDatabase();

            Connection = GetConnection(false);
            Root       = GetConnection(true);
        }
Example #27
0
        public DBControl(DBControl db)
        {
            this.serv  = db.serv;
            this.user  = db.user;
            this.passw = db.passw;
            this.db    = db.db;
            MySqlConnectionStringBuilder stringBuilder = new MySqlConnectionStringBuilder();

            stringBuilder.Server   = serv;
            stringBuilder.Password = passw;
            stringBuilder.UserID   = user;
            stringBuilder.Database = this.db;
            connection             = new MySqlConnection(stringBuilder.GetConnectionString(false));
        }
        public void PersistSecurityInfo()
        {
            MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder(Connection.ConnectionString);

            connStr.PersistSecurityInfo = false;

            Assert.False(String.IsNullOrEmpty(connStr.Password));
            MySqlConnection c = new MySqlConnection(connStr.GetConnectionString(true));

            c.Open();
            c.Close();
            connStr = new MySqlConnectionStringBuilder(c.ConnectionString);
            Assert.True(String.IsNullOrEmpty(connStr.Password));
        }
Example #29
0
        public DBController()
        {
            MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder
            {
                Server   = "158.36.13.131",
                UserID   = "dokumentpartner",
                Password = "******",
                Database = "bachelor",
                SslMode  = MySqlSslMode.None
            };

            conn = new MySqlConnection(connStr.GetConnectionString(true));
            conn.Open();
        }
        public void TestConnectingSocketBadHostName()
        {
            MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder(Connection.ConnectionString);

            connStr.Server = "foobar";
            MySqlConnection c         = new MySqlConnection(connStr.GetConnectionString(true));
            var             exception = Record.Exception(() => c.Open());

            Assert.NotNull(exception);
            Assert.IsType <MySqlException>(exception);
            MySqlException ex = exception as MySqlException;

            Assert.Equal((int)MySqlErrorCode.UnableToConnectToHost, ex.Number);
        }
Example #31
0
        public DBControl(string server, string uid, string password, string database)
        {
            serv  = server;
            user  = uid;
            passw = password;
            db    = database;
            MySqlConnectionStringBuilder stringBuilder = new MySqlConnectionStringBuilder();

            stringBuilder.Server   = serv;
            stringBuilder.UserID   = user;
            stringBuilder.Password = passw;
            stringBuilder.Database = db;
            connection             = new MySqlConnection(stringBuilder.GetConnectionString(false));
        }
Example #32
0
 public void SettingValueMultipeTimes()
 {
     MySqlConnectionStringBuilder s = new MySqlConnectionStringBuilder();
     s["database"] = "test";
     s["database"] = "test2";
     Assert.AreEqual("database=test2", s.GetConnectionString(false));
 }