Ejemplo n.º 1
0
 /// <summary>
 /// Insert soldiername and eaguid (Update soldiername if eaguid is exist).
 /// </summary>
 /// <param name="parameters"></param>
 private void InsertEAInfo(DbParameter[] parameters)
 {
     try
     {
         DbConnectionStringBuilder connectionStringBuilder = new MySqlConnectionStringBuilder();
         connectionStringBuilder.Add("server", hostName);
         connectionStringBuilder.Add("port", hostPort);
         connectionStringBuilder.Add("user", hostUser);
         connectionStringBuilder.Add("password", hostPassword);
         connectionStringBuilder.Add("database", hostDatabase);
         using (DbConnection connection = new MySqlConnection(connectionStringBuilder.ConnectionString))
         {
             connection.Open();
             using (DbTransaction transaction = connection.BeginTransaction())
             {
                 using (DbCommand command = connection.CreateCommand())
                 {
                     // select playerid by eaguid
                     command.Transaction = transaction;
                     command.Parameters.AddRange(parameters);
                     command.CommandText = string.Format(
                         "INSERT IGNORE INTO `{0}`.`{1}` (`serverid`,`gametype`,`soldiername`,`eaguid`,`firsttime`) VALUE (@serverid,@gametype,@soldiername,@eaguid,@firsttime);" +
                         "UPDATE `{0}`.`{1}` SET `soldiername` = @soldiername, `lasttime` = @lasttime WHERE eaguid = @eaguid;", hostDatabase, ClassName);
                     command.ExecuteNonQuery();
                     transaction.Commit();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Output.Error(ex.ToString());
     }
 }
Ejemplo n.º 2
0
        public static void Procedure(string sqlQuery)
        {
            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", "boatclub");
            connBuilder.Add("Data Source", "127.0.0.1");
            connBuilder.Add("User Id", "root");
            connBuilder.Add("Password", "");

            MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString);

            MySqlCommand cmd = connection.CreateCommand();

            connection.Open();
            Console.WriteLine("Anslutningen lyckades till datorbasen..");
            Console.ReadLine();

            cmd.CommandText = sqlQuery;
            cmd.CommandType = CommandType.Text;

            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine(String.Format("{0} {1} - {2}: {3} {4} {5}",
                                                reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetString(5))
                                  );
            }
            Console.ReadLine();

            reader.Close();
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            MySqlConnectionStringBuilder connBuilder =
                new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", "logicbase");
            connBuilder.Add("Data Source", "localhost");
            connBuilder.Add("User Id", "root");
            connBuilder.Add("Password", "078515");
            connBuilder.Add("Charset", "utf8");

            MySqlConnection connection =
                new MySqlConnection(connBuilder.ConnectionString);

            MySqlCommand cmd = connection.CreateCommand();

            connection.Open();

            // Here goes the code needed to perform operations on the

            this.InsertCommand(cmd, "1", "数据1");
            this.InsertCommand(cmd, "2", "数据2");

            // database such as querying or inserting rows into a table


            connection.Close();
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            // Connecting to MySQL DB
            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", "shop");
            connBuilder.Add("Data Source", "localhost");
            connBuilder.Add("User Id", "root");
            connBuilder.Add("Password", "admin#123");
            connBuilder.Add("SslMode", "none");

            MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString);

            cmd = connection.CreateCommand();

            connection.Open();

            // Build a server
            var server = new Server
            {
                Services = { GreetingService.BindService(new GreeterServiceImpl()) },
                Ports    = { new ServerPort(Host, Port, ServerCredentials.Insecure) }
            };

            // Start server
            server.Start();

            Console.WriteLine("GreeterServer listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            // Stopping MySql and Server Connection
            connection.Close();
            server.ShutdownAsync().Wait();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Update an out of date database.
        /// </summary>
        /// <param name="user">MySQL "User id" with either root access or access to the `ChatTwo` database.</param>
        /// <param name="password">Password of the user.</param>
        /// <param name="ip">IP address of the machine hosting the MySQL server.</param>
        /// <param name="port">Port number the MySQL server is running on.</param>
        public static bool UpdateDatabase(string user, string password, string ip, int port)
        {
            int cmdResult = 0;

            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("User id", user);
            connBuilder.Add("Password", password);
            connBuilder.Add("Network Address", ip);
            connBuilder.Add("Port", port);
            //connBuilder.Add("Database", "ChatTwo");
            //connBuilder.Add("Connection timeout", 5);

            using (MySqlConnection tempConn = new MySqlConnection(connBuilder.ConnectionString))
            {
                // Get the database version number from the `ServerStatus` table.
                int version = -1;
                using (MySqlCommand cmd = new MySqlCommand("SELECT `ChatTwo`.`Version` FROM `ServerStatus`;", tempConn))
                {
                    try
                    {
                        tempConn.Open();
                        // Execute SQL command.
                        MySqlDataReader reader = cmd.ExecuteReader();
                        if (reader.Read())
                        {
                            version = (int)reader["Version"];
                        }
                    }
                    finally
                    {
                        tempConn.Close();
                    }
                }

                switch (version)
                {
                case 0:
                    throw new NotImplementedException("There is no update from version 0 (yet).");

                //using (MySqlCommand cmd = new MySqlCommand("UPDATE `ServerStatus` SET `Version` = 1, `LastUpdated` = NOW();", _conn))
                //{
                //    try
                //    {
                //        Open();
                //        // Execute SQL command.
                //        cmdResult = cmd.ExecuteNonQuery();
                //    }
                //    finally
                //    {
                //        Close();
                //    }
                //}
                //break;
                default:
                    break;
                }
            }
            return(cmdResult != 0);  // cmdResult content the number of affected rows.
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="connStr">加密过的连接字符串</param>
        /// <returns></returns>
        /// <exception cref="System.NullReferenceException"></exception>
        /// <exception cref="System.Execption"></exception>
        public static MySqlConnection GetMySqlConn(string connStr)
        {
            if (string.IsNullOrEmpty(connStr))
            {
                throw new System.NullReferenceException("连接字不能为空");
            }
            string tmp = PswdHelper.DecryptString(connStr);

            string[] ss = tmp.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
            if (ss.Length != 5)
            {
                throw new Exception("连接字格式有误");
            }

            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("User Id", ss[0]);
            connBuilder.Add("Password", ss[1]);
            connBuilder.Add("Data Source", ss[2]);
            connBuilder.Add("Database", ss[3]);
            connBuilder.Add("Charset", ss[4]);

            MySqlConnection connection =
                new MySqlConnection(connBuilder.ConnectionString);

            return(connection);
        }
        /// <summary>
        /// static constructor to determine the state of the environment and set defaults
        /// </summary>
        static MySQLConnections()
        {
            // Not on cloud foundry filling in the blanks.
            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME)))
            {
                Environment.SetEnvironmentVariable(BOUND_SERVICES_ENV_VARIABLE_NAME, "{}");
                Environment.SetEnvironmentVariable(PORT_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
                Environment.SetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
                Environment.SetEnvironmentVariable(INSTANCE_INDEX_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
            }

            if (BoundServices.GetValue("p.mysql") != null)
            {
                DbEngine = DatabaseEngine.MySql;;
                MySqlConnectionStringBuilder csbuilder = new MySqlConnectionStringBuilder();
                csbuilder.Add("server", BoundServices["p.mysql"][0]["credentials"]["hostname"].ToString());
                csbuilder.Add("port", BoundServices["p.mysql"][0]["credentials"]["port"].ToString());
                csbuilder.Add("uid", BoundServices["p.mysql"][0]["credentials"]["username"].ToString());
                csbuilder.Add("pwd", BoundServices["p.mysql"][0]["credentials"]["password"].ToString());
                csbuilder.Add("database", BoundServices["p.mysql"][0]["credentials"]["name"].ToString());
                _connectionString = csbuilder.ToString();
            }
            else
            {
                DbEngine = DatabaseEngine.None;
            }
        }
Ejemplo n.º 8
0
        public void TestDatabase()
        {
            DbConnectionStringBuilder connectionStringBuilder = new MySqlConnectionStringBuilder();

            connectionStringBuilder.Add("server", hostName);
            connectionStringBuilder.Add("port", hostPort);
            connectionStringBuilder.Add("user", hostUser);
            connectionStringBuilder.Add("password", hostPassword);
            connectionStringBuilder.Add("database", hostDatabase);
            try
            {
                using (DbConnection connection = new MySqlConnection(connectionStringBuilder.ConnectionString))
                {
                    connection.Open();
                }
                retryTestCount = 0;
            }
            catch (Exception ex)
            {
                Output.Error(ex.ToString());
                if (retryTestCount++ > 5)
                {
                    retryTestCount = 0;
                    Output.Error("{0} is disable", ClassName);
                    EnablePlugin(false);
                }
            }
        }
Ejemplo n.º 9
0
    /// <summary>
    /// static constructor to determine the state of the environment and set defaults
    /// </summary>
    static CurrentEnvironment()
    {
        // Not on cloud foundry filling in the blanks.
        if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME)))
        {
            Environment.SetEnvironmentVariable(BOUND_SERVICES_ENV_VARIABLE_NAME, "{}");
            Environment.SetEnvironmentVariable(PORT_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
            Environment.SetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
            Environment.SetEnvironmentVariable(INSTANCE_INDEX_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
        }

        // check to see if DB is bound, if so...what type
        // sql server first
        if (BoundServices.GetValue("mssql-dev") != null) // sql server
        {
            DbEngine          = DatabaseEngine.SqlServer;
            _connectionString = BoundServices["mssql-dev"][0]["credentials"]["connectionString"].ToString();
        }
        else if (BoundServices.GetValue("p-mysql") != null)
        {
            DbEngine = DatabaseEngine.MySql;;
            MySqlConnectionStringBuilder csbuilder = new MySqlConnectionStringBuilder();
            csbuilder.Add("server", BoundServices["p-mysql"][0]["credentials"]["hostname"].ToString());
            csbuilder.Add("port", BoundServices["p-mysql"][0]["credentials"]["port"].ToString());
            csbuilder.Add("uid", BoundServices["p-mysql"][0]["credentials"]["username"].ToString());
            csbuilder.Add("pwd", BoundServices["p-mysql"][0]["credentials"]["password"].ToString());
            csbuilder.Add("database", BoundServices["p-mysql"][0]["credentials"]["name"].ToString());
            _connectionString = csbuilder.ToString();
        }
        else
        {
            DbEngine = DatabaseEngine.None;
        }
    }
Ejemplo n.º 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            MySqlConnection con      = null;
            string          user     = txtUser.Text;
            string          password = txtPassword.Text;
            string          server   = txtServer.Text;

            MySqlConnectionStringBuilder mssb = new MySqlConnectionStringBuilder();

            mssb.Add("user id", user);
            if (!String.IsNullOrEmpty(password))
            {
                mssb.Add("password", password);
            }
            mssb.Add("server", server);
            mssb.Add("database", txtDatabase.Text);

            try
            {
                Connection.ConnectionString = mssb.ConnectionString;
                con = Connection.getConnection();
                con.Open();
                this.DialogResult = DialogResult.OK;
            }
            catch (MySqlException ex)
            {
                FrameworkControls.Classes.PanException.Show(this, ex);
            }
            finally
            {
                con.Close();
            }
        }
Ejemplo n.º 11
0
        public static void DeleteBoatSQL(string sqlQuery)
        {
            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", "boatclub");
            connBuilder.Add("Data Source", "127.0.0.1");
            connBuilder.Add("User Id", "root");
            connBuilder.Add("Password", "");

            MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString);

            MySqlCommand cmd = connection.CreateCommand();

            connection.Open();

            cmd.CommandText = sqlQuery;
            cmd.CommandType = CommandType.Text;

            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                Console.WriteLine(String.Format("{0} {1} {2}",
                                                reader.GetInt32(0), reader.GetString(1), reader.GetString(2))
                                  );
            }
            reader.Close();
        }
Ejemplo n.º 12
0
        public DatabaseDriver()
        {
            this.DatabaseEngine = Config.GetDatabaseEngine();

            DbConnectionStringBuilder Builder;

            if (this.DatabaseEngine == DatabaseEngine.Sqlite)
            {
                Builder = new SQLiteConnectionStringBuilder();
                string FullPath = Path.Combine(Utils.AssemblyPath, Config.GetType <string>("Database", "Database") + ".sqlite3");
                IsNewDatabase = !File.Exists(FullPath) || new FileInfo(FullPath).Length == 0;

                Builder.Add("Data Source", FullPath);

                Connection = new SQLiteConnection(Builder.ConnectionString);
            }
            else if (this.DatabaseEngine == DatabaseEngine.Mysql)
            {
                Builder = new MySqlConnectionStringBuilder();

                Builder.Add("Server", Config.GetType <string>("Database", "Hostname"));
                Builder.Add("Port", Config.GetType <int>("Database", "Port"));
                Builder.Add("User ID", Config.GetType <string>("Database", "Username"));
                Builder.Add("Password", Config.GetType <string>("Database", "Password"));
                Builder.Add("Database", Config.GetType <string>("Database", "Database"));

                Connection = new MySqlConnection(Builder.ConnectionString);
            }
            else
            {
                throw new Exception("Invalid Database type.");
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Create database by <see cref="hostDatabase"/> if not exist.
        /// </summary>
        private void InitDatabase()
        {
            DbConnectionStringBuilder connectionStringBuilder = new MySqlConnectionStringBuilder();

            connectionStringBuilder.Add("server", hostName);
            connectionStringBuilder.Add("port", hostPort);
            connectionStringBuilder.Add("user", hostUser);
            connectionStringBuilder.Add("password", hostPassword);
            try
            {
                using (DbConnection connection = new MySqlConnection(connectionStringBuilder.ConnectionString))
                {
                    connection.Open();
                    using (DbTransaction transaction = connection.BeginTransaction())
                    {
                        try
                        {
                            using (DbCommand command = connection.CreateCommand())
                            {
                                command.Transaction = transaction;
                                command.CommandText = string.Format("CREATE DATABASE if NOT EXISTS `{0}`", hostDatabase);
                                command.ExecuteNonQuery();
                                command.CommandText = string.Format("USE `{0}`", hostDatabase);
                                command.ExecuteNonQuery();
                                command.CommandText = string.Format("CREATE TABLE IF NOT EXISTS `{0}` (" +
                                                                    "`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT," +
                                                                    "`gameid` INT(10) UNSIGNED NOT NULL DEFAULT '0'," +
                                                                    "`ipaddress` VARCHAR(22) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci'," +
                                                                    "`clantag` VARCHAR(5) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci'," +
                                                                    "`soldiername` VARCHAR(20) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci'," +
                                                                    "`eaguid` VARCHAR(35) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci'," +
                                                                    "`pbguid` VARCHAR(32) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci'," +
                                                                    "`country` VARCHAR(30) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci'," +
                                                                    "`countrycode` VARCHAR(10) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci'," +
                                                                    "PRIMARY KEY(`id`), UNIQUE INDEX `Index 2` (`eaguid`), UNIQUE INDEX `Index 3` (`pbguid`)" +
                                                                    ") COLLATE = 'utf8mb4_general_ci'", ClassName);
                                command.ExecuteNonQuery();
                                transaction.Commit();
                            }
                        }
                        catch
                        {
                            transaction.Rollback();
                            throw;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Output.WriteLine("-------------------");
                Output.Error(ex.ToString());
            }
        }
Ejemplo n.º 14
0
        public MySqlConnection DatabaseSettings()
        {
            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", "boatclub");
            connBuilder.Add("Data Source", "127.0.0.1");
            connBuilder.Add("User Id", "root");
            connBuilder.Add("Password", "");
            MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString);

            return(connection);
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            int rowsAffected = 0;

            StringBuilder insertCommand = new StringBuilder();

            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", "Results_MakeCluster_Algorithm");
            connBuilder.Add("Data Source", "localhost");
            connBuilder.Add("User Id", "root");
            connBuilder.Add("Password", "***");  //change this line before running

            MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString);
            MySqlCommand    cmd        = connection.CreateCommand();

            connection.Open();

            for (int number = 0; number < 1000; number++)
            {
                Graph           graph    = new Graph();
                List <string>[] clusters = new List <string> [21];

                for (int i = 0; i < 21; i++)
                {
                    clusters[i] = MakeCycles(graph);
                }

                clusters = PostProcess(clusters, graph);

                insertCommand.Append("INSERT INTO Finished_Clusters VALUES (");
                insertCommand.Append(number.ToString() + ", ");

                for (int j = 0; j < clusters.Length; j++)
                {
                    insertCommand.Append(ListToString(clusters[j]) + ",");
                }

                insertCommand.Append(ComputeObjFunction(clusters, graph).ToString() + ");");

                cmd.CommandText = insertCommand.ToString();

                rowsAffected += cmd.ExecuteNonQuery();

                insertCommand.Clear();
            }

            connection.Close();

            Console.WriteLine(rowsAffected);

            Console.ReadKey();
        }
Ejemplo n.º 16
0
        static DB()
        {
            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", "Project_JJK");
            connBuilder.Add("Data Source", "hellojkw.com");
            connBuilder.Add("User Id", "uj7380");
            connBuilder.Add("Password", "uj7380");

            _connectionString = connBuilder.ToString();
            Conn = new MySqlConnection(_connectionString);
        }
 static PCFEnvironment()
 {
     if (BoundServices.GetValue("p-mysql") != null)
     {
         MySqlConnectionStringBuilder csbuilder = new MySqlConnectionStringBuilder();
         csbuilder.Add("server", BoundServices["p-mysql"][0]["credentials"]["hostname"].ToString());
         csbuilder.Add("port", BoundServices["p-mysql"][0]["credentials"]["port"].ToString());
         csbuilder.Add("uid", BoundServices["p-mysql"][0]["credentials"]["username"].ToString());
         csbuilder.Add("pwd", BoundServices["p-mysql"][0]["credentials"]["password"].ToString());
         csbuilder.Add("database", BoundServices["p-mysql"][0]["credentials"]["name"].ToString());
         _connectionString = csbuilder.ToString();
     }
 }
Ejemplo n.º 18
0
        public MySqlConnection GetConnection()
        {
            MySqlConnectionStringBuilder connectionStringBuilder = new MySqlConnectionStringBuilder();

            connectionStringBuilder.Add("Database", "test");
            connectionStringBuilder.Add("Data Source", "localhost");
            connectionStringBuilder.Add("User Id", "root");
            connectionStringBuilder.Add("Password", "");

            dbConnection = new MySqlConnection(connectionStringBuilder.ConnectionString);

            return(dbConnection);
        }
Ejemplo n.º 19
0
    public MySqlConnectionStringBuilder Conn_buildder()
    {
        MySqlConnectionStringBuilder connBuilder =
            new MySqlConnectionStringBuilder();

        connBuilder.Add("Database", "pdbsoral");
        // connBuilder.Add("Data Source", "10.95.14.153");
        connBuilder.Add("Data Source", "10.82.14.237");
        connBuilder.Add("User Id", "khoamap");
        connBuilder.Add("Password", "123456");
        connBuilder.Add("Charset", "utf8");

        return(connBuilder);
    }
Ejemplo n.º 20
0
    /// <summary>
    /// static constructor to determine the state of the environment and set defaults
    /// </summary>
    static CurrentEnvironment()
    {
        // Not on cloud foundry filling in the blanks.
        if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME)))
        {
            Environment.SetEnvironmentVariable(BOUND_SERVICES_ENV_VARIABLE_NAME, "{}");
            Environment.SetEnvironmentVariable(PORT_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
            Environment.SetEnvironmentVariable(INSTANCE_GUID_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
            Environment.SetEnvironmentVariable(INSTANCE_INDEX_ENV_VARIABLE_NAME, NOT_ON_CLOUD_FOUNDRY_MESSAGE);
        }

        // check to see if DB is bound, if so...what type
        // SQL server first
        if (BoundServices.GetValue("azure-sqldb") != null) // Azure SQL Database (Azure Broker)
        {
            DbEngine = DatabaseEngine.SqlServer;
            SqlConnectionStringBuilder csbuilder = new SqlConnectionStringBuilder();
            csbuilder.Add("server", BoundServices["azure-sqldb"][0]["credentials"]["hostname"].ToString());
            csbuilder.Add("uid", BoundServices["azure-sqldb"][0]["credentials"]["username"].ToString());
            csbuilder.Add("pwd", BoundServices["azure-sqldb"][0]["credentials"]["password"].ToString());
            csbuilder.Add("database", BoundServices["azure-sqldb"][0]["credentials"]["name"].ToString());
            _connectionString = csbuilder.ToString();
        }
        else if (BoundServices.GetValue("azure-mysqldb") != null || BoundServices.GetValue("p-mysql") != null || BoundServices.GetValue("cleardb") != null) // MySQL for PCF or Mysql for AZURE
        {
            string label = "p-mysql";                                                                                                                       // MySQL Database.

            if (BoundServices.GetValue("azure-mysqldb") != null)
            {
                label = "azure-mysqldb"; //Mysql Database on Azure (Mysql For Azure)
            }
            if (BoundServices.GetValue("cleardb") != null)
            {
                label = "cleardb"; //Mysql cleardb
            }
            DbEngine = DatabaseEngine.MySql;
            MySqlConnectionStringBuilder csbuilder = new MySqlConnectionStringBuilder();
            csbuilder.Add("server", BoundServices[label][0]["credentials"]["hostname"].ToString());
            csbuilder.Add("port", BoundServices[label][0]["credentials"]["port"].ToString());
            csbuilder.Add("uid", BoundServices[label][0]["credentials"]["username"].ToString());
            csbuilder.Add("pwd", BoundServices[label][0]["credentials"]["password"].ToString());
            csbuilder.Add("database", BoundServices[label][0]["credentials"]["name"].ToString());
            _connectionString = csbuilder.ToString();
        }
        else
        {
            DbEngine = DatabaseEngine.None;
        }
    }
Ejemplo n.º 21
0
        /// <summary>
        /// Create database by <see cref="hostDatabase"/> if not exist.
        /// </summary>
        private void InitDatabase()
        {
            DbConnectionStringBuilder connectionStringBuilder = new MySqlConnectionStringBuilder();

            connectionStringBuilder.Add("server", hostName);
            connectionStringBuilder.Add("port", hostPort);
            connectionStringBuilder.Add("user", hostUser);
            connectionStringBuilder.Add("password", hostPassword);
            connectionStringBuilder.Add("database", hostDatabase);
            try
            {
                using (DbConnection connection = new MySqlConnection(connectionStringBuilder.ConnectionString))
                {
                    connection.Open();
                    using (DbTransaction transaction = connection.BeginTransaction())
                    {
                        using (DbCommand command = connection.CreateCommand())
                        {
                            command.Transaction = transaction;
                            command.CommandText = string.Format("CREATE TABLE IF NOT EXISTS `{0}`.`{1}` (" +
                                                                "`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT," +
                                                                "`serverid` INT(10) DEFAULT NULL," +
                                                                "`gametype` VARCHAR(10) NULL DEFAULT NULL," +
                                                                "`ipaddress` VARCHAR(22) NULL DEFAULT NULL," +
                                                                "`clantag` VARCHAR(5) NULL DEFAULT NULL," +
                                                                "`soldiername` VARCHAR(20) NULL DEFAULT NULL," +
                                                                "`eaguid` VARCHAR(35) NULL DEFAULT NULL ," +
                                                                "`pbguid` VARCHAR(32) NULL DEFAULT NULL ," +
                                                                "`country` VARCHAR(30) NULL DEFAULT NULL ," +
                                                                "`countrycode` VARCHAR(10) NULL DEFAULT NULL ," +
                                                                "`firsttime` datetime DEFAULT NULL," +
                                                                "`lasttime` datetime DEFAULT NULL," +
                                                                "PRIMARY KEY(`id`), " +
                                                                "UNIQUE INDEX `Index 2` (`eaguid`), " +
                                                                "UNIQUE INDEX `Index 3` (`pbguid`)" +
                                                                ")", hostDatabase, ClassName);
                            command.ExecuteNonQuery();
                            transaction.Commit();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Output.WriteLine("-------------------");
                Output.Error(ex.ToString());
            }
        }
Ejemplo n.º 22
0
        public DBManager()
        {
            server   = "localhost";
            database = "snus_shema";
            uid      = "root";
            pass     = "******";

            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", database);
            connBuilder.Add("Data Source", server);
            connBuilder.Add("User Id", uid);
            connBuilder.Add("Password", pass);

            connection = new MySqlConnection(connBuilder.ConnectionString);
        }
Ejemplo n.º 23
0
 public static void connect()
 {
     connBuilder.Add("Database", "rover");
     connBuilder.Add("Data Source", "localhost");
     connBuilder.Add("User Id", "root");
     connBuilder.Add("Password", "");
     connection = new MySqlConnection(connBuilder.ConnectionString);
     cmd        = connection.CreateCommand();
     try
     {
         connection.Open();
         IrcBot.log += "MYSQL connection ready\n";
     }
     catch
     {
         IrcBot.log += "MYSQL isn't running!!!\n";
     }
 }
Ejemplo n.º 24
0
        public override void initialize_connections(ConfigurationPropertyHolder configuration_property_holder)
        {
            if (!string.IsNullOrEmpty(connection_string))
            {
                // Must allow User variables for SPROCs
                var connectionBuilder = new MySqlConnectionStringBuilder(connection_string);
                if (!connectionBuilder.AllowUserVariables)
                {
                    connectionBuilder.Add("Allow User Variables", "True");
                    connection_string = connectionBuilder.ConnectionString;
                }

                string[] parts = connection_string.Split(';');
                foreach (string part in parts)
                {
                    if (string.IsNullOrEmpty(server_name) && (part.to_lower().Contains("server") || part.to_lower().Contains("data source")))
                    {
                        server_name = part.Substring(part.IndexOf("=") + 1);
                    }

                    if (string.IsNullOrEmpty(database_name) && (part.to_lower().Contains("database") || part.to_lower().Contains("database")))
                    {
                        database_name = part.Substring(part.IndexOf("=") + 1);
                    }
                }
            }

            if (server_name == infrastructure.ApplicationParameters.default_server_name)
            {
                server_name = "localhost";
            }

            if (string.IsNullOrEmpty(connection_string))
            {
                InteractivePrompt.write_header(configuration_property_holder);
                var user_name = InteractivePrompt.get_user("root", configuration_property_holder);
                var password  = InteractivePrompt.get_password("root", configuration_property_holder);
                InteractivePrompt.write_footer();

                connection_string = build_connection_string(server_name, database_name, user_name, password);
            }

            configuration_property_holder.ConnectionString = connection_string;

            set_provider();
            if (string.IsNullOrEmpty(admin_connection_string))
            {
                var builder = new MySqlConnectionStringBuilder(connection_string);
                builder.Database        = "information_schema";
                admin_connection_string = builder.ConnectionString;
            }
            configuration_property_holder.ServerName            = server_name;
            configuration_property_holder.DatabaseName          = database_name;
            configuration_property_holder.ConnectionStringAdmin = admin_connection_string;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Creates a new connection to the database
        /// </summary>
        /// <returns></returns>
        private MySqlConnection GetConnection()
        {
            //Credentials
            string user     = "******";
            string pass     = "******";
            string server   = "server";
            string database = "database";

            //Create the Connection String
            MySqlConnectionStringBuilder mscsb = new MySqlConnectionStringBuilder();

            mscsb.Add("Server", server);
            mscsb.Add("Database", database);
            mscsb.Add("User", user);
            mscsb.Add("Password", pass);
            mscsb.Add("Connection Timeout", 120);

            //Return a new connection using the connection string
            return(new MySqlConnection(mscsb.ToString()));
        }
Ejemplo n.º 26
0
        public MySqlConnection openconnection()
        {
            try
            {
                MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

                connBuilder.Add("Database", "pharmacy");
                connBuilder.Add("Data Source", "localhost");
                connBuilder.Add("User Id", "root");
                connBuilder.Add("Password", "your data base password");

                conn = new MySqlConnection(connBuilder.ConnectionString);
                conn.Open();
                return(conn);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(conn);
        }
        public new List <string> Init()
        {
            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", database);
            connBuilder.Add("Data Source", "localhost");
            connBuilder.Add("User Id", "root");
            connBuilder.Add("Password", "Rhino1515");

            MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString);

            MySqlCommand cmd = connection.CreateCommand();

            connection.Open();

            cmd.CommandText = "SELECT * FROM fish";
            cmd.CommandType = CommandType.Text;

            MySqlDataReader reader    = cmd.ExecuteReader();
            var             elegetter = new BuildTable();

            var Elements = elegetter.GetElements();

            var list = new List <string>();

            while (reader.Read())
            {
                var temp = new StringBuilder();
                for (int i = 0; i < 25; i++)
                {
                    temp.Append(reader[Elements[i]]).Append(",");
                }
                list.Add(temp.ToString());
            }
            connection.Close();
            return(list);
        }
Ejemplo n.º 28
0
        public void conn()
        {
           
            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", "pharmacy");
            connBuilder.Add("Data Source", "localhost");
            connBuilder.Add("User Id", "root");
            connBuilder.Add("Password", "24hoursnaya");

            connection = new MySqlConnection(connBuilder.ConnectionString);

            if (ok == 1) { Console.WriteLine("giye na"); }
            else
            {
                Console.WriteLine("yanne na");
                connection.Open();
                ok = 1;
                Console.WriteLine(ok);
            }

            // connection.Open();
         
        }
Ejemplo n.º 29
0
        public static string GetMySqlConnectionString(this IConfiguration configuration, bool ignoreDbName = false)
        {
            var ssb     = new MySqlConnectionStringBuilder();
            var section = configuration.GetSection("ConnectionProps");

            foreach (var s in section.GetChildren())
            {
                if (ignoreDbName && s.Key == "Database" || s.Value == null)
                {
                    continue;
                }

                ssb.Add(s.Key, s.Value);
            }

            return(ssb.ToString());
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Generate connection string with the given properties
        /// </summary>
        /// <param name="connectionDto">Connection details</param>
        /// <returns>Connection string of the database</returns>
        private static string GenerateConnectionString(ConnectionDto connectionDto)
        {
            DbConnectionStringBuilder connectionBuilder = null;

            string connectionString = string.Empty;

            connectionBuilder = new MySqlConnectionStringBuilder();

            if (connectionBuilder != null)
            {
                // Populate connection builder with connection properties
                foreach (KeyValuePair <string, string> property in connectionDto.Properties)
                {
                    if (connectionBuilder.ContainsKey(property.Key) && !string.IsNullOrEmpty(property.Value))
                    {
                        connectionBuilder.Add(property.Key, property.Value);
                    }
                }
                connectionString = connectionBuilder.ConnectionString;
                connectionDto.ConnectionString = connectionString;
            }
            return(connectionString);
        }