当前位置: 首页>>代码示例>>C#>>正文


C# MySqlClient.MySqlConnectionStringBuilder类代码示例

本文整理汇总了C#中MySql.Data.MySqlClient.MySqlConnectionStringBuilder的典型用法代码示例。如果您正苦于以下问题:C# MySqlConnectionStringBuilder类的具体用法?C# MySqlConnectionStringBuilder怎么用?C# MySqlConnectionStringBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MySqlConnectionStringBuilder类属于MySql.Data.MySqlClient命名空间,在下文中一共展示了MySqlConnectionStringBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Command

 public static void Command(string command)
 {
     try
     {
         var connstring = new MySqlConnectionStringBuilder
                              {
                                  Server = meh.Default.MysqlHost,
                                  UserID = meh.Default.MysqlUsername,
                                  Password = meh.Default.MysqlPassword,
                                  Database = meh.Default.MysqlDatabase
                              };
         var connection = new MySqlConnection(connstring.ToString());
         LogWriter.WriteLine(@"opening connection to mysql");
         connection.Open();
         LogWriter.WriteLine(@"connection successful!");
         var sqlcommand = new MySqlCommand(command, connection);
         LogWriter.WriteLine(@"Running sql command");
         sqlcommand.ExecuteNonQuery();
         LogWriter.WriteLine(@"Sql Command finished.");
     }
     catch (Exception ex)
     {
         MessageBox.Show(@"An Error occured while importing the file!, log output should have more info.");
         LogWriter.WriteLine(ex.Data + ex.StackTrace + ex.Message);
     }
 }
开发者ID:jaddie,项目名称:WCellDatabaseImportSystem,代码行数:26,代码来源:MysqlHandler.cs

示例2: TestBtn_Click

        private void TestBtn_Click(object sender, EventArgs e)
        {
            // Disable console
            this.Enabled = false;

            // Build Connection String
            DbConnectionStringBuilder Builder = new MySqlConnectionStringBuilder();
            Builder.Add("Server", Hostname.Text);
            Builder.Add("Port", (int)Port.Value);
            Builder.Add("User ID", Username.Text);
            Builder.Add("Password", Password.Text);
            Builder.Add("Database", DBName.Text);

            // Attempt to connect, reporting any and all errors
            try
            {
                MySqlConnection Connection = new MySqlConnection(Builder.ConnectionString);
                Connection.Open();
                Connection.Close();
            }
            catch(Exception E)
            {
                this.Enabled = true;
                MessageBox.Show(E.Message, "Connection Error");
                return;
            }

            MessageBox.Show("Connection Successful!", "Success");
            this.Enabled = true;
        }
开发者ID:roguesupport,项目名称:ControlCenter,代码行数:30,代码来源:GamespyConfig.cs

示例3: Connect

        public override bool Connect() {
            bool opened = true;

            if (this.Connection == null || this.Connection.State == ConnectionState.Closed) {
                if (this.Connection != null) {
                    this.Connection.Close();
                    this.Connection = null;
                }

                MySqlConnectionStringBuilder connectionBuilder = new MySqlConnectionStringBuilder {
                    Server = this.Settings.Hostname,
                    Port = this.Settings.Port != null ? this.Settings.Port.Value : 0,
                    Database = this.Settings.Database,
                    UserID = this.Settings.Username,
                    Password = this.Settings.Password,
                    UseCompression = true
                };

                try {
                    this.Connection = new MySqlConnection(connectionBuilder.ToString());
                    this.Connection.Open();

                    if (this.Connection.State != ConnectionState.Open) {
                        this.Connection.Close();
                        this.Connection = null;
                    }
                }
                catch {
                    opened = false;
                }
            }

            return opened;
        }
开发者ID:EBassie,项目名称:Potato,代码行数:34,代码来源:MySqlDriver.cs

示例4: ClearPool

        public static void ClearPool(MySqlConnectionStringBuilder settings)
        {
            Debug.Assert(settings != null);

            string text = settings.ConnectionString;
            ClearPoolByText(text);
        }
开发者ID:elevate,项目名称:mysqlconnector-.net,代码行数:7,代码来源:MySqlPoolManager.cs

示例5: DeleteBoatSQL

        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();
        }
开发者ID:DevRobDev,项目名称:1DV407,代码行数:28,代码来源:SQLconnection.cs

示例6: ConnectionStringDialog

 /// <summary>
 /// Default Constructor
 /// </summary>
 public ConnectionStringDialog()
 {
     InitializeComponent();
     this.cmbServerName.Items.Add("<Browse for more>");
     this.cmbServerName.Text = "";
     dbConnectionStringBuilder = new MySqlConnectionStringBuilder();
 }
开发者ID:NALSS,项目名称:epiinfo-82474,代码行数:10,代码来源:ConnectionStringDialog.cs

示例7: Serialize

        public static SerializeResult Serialize()
        {
            try
            {
                var Builder = new MySqlConnectionStringBuilder();
                Builder.Server = Settings.GetValue("Database.Host");
                Builder.Port = uint.Parse(Settings.GetValue("Database.Port"));
                Builder.UserID = Settings.GetValue("Database.Username");
                Builder.Password = Settings.GetValue("Database.Password");
                Builder.Database = Settings.GetValue("Database.Database");
                Builder.Pooling = Settings.GetValue("Database.Pooling.Enabled").ToLower() == "true";
                Builder.MinimumPoolSize = uint.Parse(Settings.GetValue("Database.Pooling.Min"));
                Builder.MaximumPoolSize = uint.Parse(Settings.GetValue("Database.Pooling.Max"));

                ConnectionString = Builder.ConnectionString;

                var Connection = new MySqlConnection(ConnectionString);
                Connection.Open();

                Solution.AppendLine("DatabaseHandler: Connected with database: {0}({1})", Connection.Database, Connection.ServerVersion);
            }
            catch { return SerializeResult.Broken; }

            return SerializeResult.Finished;
        }
开发者ID:devBoolean,项目名称:Boolean,代码行数:25,代码来源:DatabaseHandler.cs

示例8: DatabaseDriver

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Engine">The string name, from the GetDatabaseEngine() method</param>
        /// <param name="Host">The Database server IP Address</param>
        /// <param name="Port">The Database server Port Number</param>
        /// <param name="DatabaseName">The name of the database</param>
        /// <param name="User">A username, with database privliages</param>
        /// <param name="Pass">The password to the User</param>
        public DatabaseDriver(string Engine, string Host, int Port, string DatabaseName, string User, string Pass)
        {
            // Set class variables, and create a new connection builder
            this.DatabaseEngine = GetDatabaseEngine(Engine);
            DbConnectionStringBuilder Builder;

            if (this.DatabaseEngine == DatabaseEngine.Sqlite)
            {
                string FullPath = Path.Combine(MainForm.Root, DatabaseName + ".sqlite3");
                IsNewDatabase = !File.Exists(FullPath) || new FileInfo(FullPath).Length == 0;
                Builder = new SQLiteConnectionStringBuilder();
                Builder.Add("Data Source", FullPath);
                Connection = new SQLiteConnection(Builder.ConnectionString);
            }
            else if (this.DatabaseEngine == DatabaseEngine.Mysql)
            {
                IsNewDatabase = false;
                Builder = new MySqlConnectionStringBuilder();
                Builder.Add("Server", Host);
                Builder.Add("Port", Port);
                Builder.Add("User ID", User);
                Builder.Add("Password", Pass);
                Builder.Add("Database", DatabaseName);
                Connection = new MySqlConnection(Builder.ConnectionString);
            }
            else
            {
                throw new Exception("Invalid Database type.");
            }
        }
开发者ID:JohannesHei,项目名称:ControlCenter,代码行数:39,代码来源:DatabaseDriver.cs

示例9: CreateDatabaseAsync

        public static Task CreateDatabaseAsync(this MySqlDatabase db)
        {

            return Task.Run(() =>
            {

                MySqlConnectionStringBuilder connStr = new MySqlConnectionStringBuilder();
                connStr.Server = db.Host;
                connStr.Port = (uint)db.Port;
                connStr.UserID = db.Username;
                connStr.Password = db.Password;
                
                string connString = connStr.ToString();

                string nonQuery = String.Format("DROP DATABASE IF EXISTS {0}; CREATE DATABASE {0};", db.DatabaseName);

                using (MySqlConnection conn = new MySqlConnection(connString))
                {

                    conn.Open();

                    using (MySqlCommand cmd = new MySqlCommand(nonQuery, conn))
                    {
                        cmd.ExecuteNonQuery();
                    }

                    conn.Close();
                
                }

            });

        }
开发者ID:TrinityCore-Manager,项目名称:TrinityCore-Manager-v3,代码行数:33,代码来源:MySqlHelper.cs

示例10: initialize_connections

        public override void initialize_connections(ConfigurationPropertyHolder configuration_property_holder)
        {
            if (!string.IsNullOrEmpty(connection_string))
            {
                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);
                    }
                }
            }

            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;
            }
        }
开发者ID:mjmeintjes,项目名称:roundhouse,代码行数:29,代码来源:MySqlDatabase.cs

示例11: get_clients

    // API GO
    // Запросы на получение
    public DataTable get_clients()
    {
        DataTable dt = new DataTable();
        MySqlConnectionStringBuilder mysqlCSB;
        mysqlCSB = new MySqlConnectionStringBuilder();
        mysqlCSB.Server = server;
        mysqlCSB.Database = db;
        mysqlCSB.UserID = user;
        mysqlCSB.Password = pass;
        string queryString = @"SELECT *              
                          FROM   clients";

        using (MySqlConnection con = new MySqlConnection())
        {
            con.ConnectionString = mysqlCSB.ConnectionString;
            MySqlCommand com = new MySqlCommand(queryString, con);
            try
            {
                con.Open();
                using (MySqlDataReader dr = com.ExecuteReader())
                {
                    if (dr.HasRows)
                    {
                        dt.Load(dr);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        return dt;
    }
开发者ID:trase8,项目名称:kurs,代码行数:36,代码来源:Form1.cs

示例12: WizardSelectDatabaseViewModel

        public WizardSelectDatabaseViewModel(WizardSelectDatabaseModel model, string host, int port, string username, string password)
        {

            WizardSelectDatabase = model;

            OkCommand = new Command(Ok);
            CancelCommand = new Command(CancelCmd);

            var connStr = new MySqlConnectionStringBuilder();
            connStr.Server = host;
            connStr.Port = (uint)port;
            connStr.UserID = username;
            connStr.Password = password;

            using (var connection = new MySqlConnection(connStr.ToString()))
            {
                connection.Open();

                using (var returnVal = new MySqlDataAdapter("SHOW DATABASES", connection))
                {

                    var dataTable = new DataTable();
                    returnVal.Fill(dataTable);

                    foreach (DataRow row in dataTable.Rows)
                        for (int i = 0; i < row.ItemArray.Length; i++)
                            Databases.Add(row.ItemArray[i].ToString());

                }

            }

        }
开发者ID:TrinityCore-Manager,项目名称:TrinityCore-Manager-v3,代码行数:33,代码来源:WizardSelectDatabaseViewModel.cs

示例13: MySqlConnection

        // Передача параметров подключения фенкции, с последующим назначением свойств.
        /// <summary>
        /// Метод MySqlConnection. Устанавливает подлючение к БД.
        /// </summary>
        public static bool MySqlConnection(string user, string passwd, string host, string db, bool test)
        {
            User = user;
            Pass = passwd;
            Host = host;
            DB = db;

            MySqlConnectionStringBuilder mysqlSting = new MySqlConnectionStringBuilder();

            mysqlSting.Server = Host;
            mysqlSting.Database = DB;
            mysqlSting.UserID = User;
            mysqlSting.Password = Pass;
            mysqlSting.CharacterSet = "utf8";

            connection = new MySqlConnection(mysqlSting.ToString());
            {
                try
                {
                    connection.Open();
                    connection.Close();
                    return true;
                }
                catch { return false; }
            }
        }
开发者ID:ruhex,项目名称:ais,代码行数:30,代码来源:MySQL.cs

示例14: DataTable

        DataTable dt_dr = new DataTable(); // tek tablo

        #endregion Fields

        #region Constructors

        public Form3(MySqlConnectionStringBuilder _bag)
        {
            InitializeComponent();

            MySqlConnection conn = new MySqlConnection(_bag.ToString());
            MySqlCommand cmd_hasta_sel = new MySqlCommand("select h.tc,h.adsoyad,d.doktorad from hasta h inner join doktor d on d.iddoktor=h.iddr;", conn);
            da_hasta = new MySqlDataAdapter();
            da_hasta.SelectCommand = cmd_hasta_sel;

            MySqlCommand cmd_dr_sel = new MySqlCommand("select iddoktor, doktorad from doktor;", conn);
            MySqlDataAdapter da_dr = new MySqlDataAdapter();
            da_dr.SelectCommand = cmd_dr_sel;
            da_dr.Fill(dt_dr); // doktorlarin listesi

            da_hasta_ekle = new MySqlDataAdapter(); // hasta eklemek icin
            MySqlCommand cmdhasta_sel = new MySqlCommand("select tc, adsoyad, iddr from hasta;", conn);
            MySqlCommand cmdhasta_ins = new MySqlCommand("insert into hasta(tc, adsoyad, iddr) values(@tc, @adsoyad, @iddr);", conn);
            cmdhasta_ins.Parameters.Add("@tc", MySqlDbType.VarChar, 11, "tc");
            cmdhasta_ins.Parameters.Add("@adsoyad", MySqlDbType.VarChar, 45, "adsoyad");
            cmdhasta_ins.Parameters.Add("@iddr", MySqlDbType.Int32, 11, "iddr");

            da_hasta_ekle.SelectCommand = cmdhasta_sel;
            da_hasta_ekle.InsertCommand = cmdhasta_ins;

            verigetir();

            // doktorlarin listesini comboya
            for (int i = 0; i < dt_dr.Rows.Count; i++)
                cdoktor.Items.Add(dt_dr.Rows[i].ItemArray[1].ToString());
        }
开发者ID:ahmetserefoglu,项目名称:csharpchatuygulamasi,代码行数:36,代码来源:Form3.cs

示例15: BuildConnectionString

        private string BuildConnectionString()
        {
            uint port = 0;
            try
            {
                port = Convert.ToUInt32(this.portTB.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Invalid port number.");
                return null;
            }

            MySqlConnectionStringBuilder bldr = new MySqlConnectionStringBuilder();
            bldr.Server = this.hostTB.Text.Trim();
            bldr.Port = port;
            bldr.UserID = this.userTB.Text.Trim();
            bldr.Database = this.dbTB.Text.Trim();
            bldr.Password = this.passwordTB.Text;

            if (this.useSslCB.Checked)
            {
                bldr.SslMode = MySqlSslMode.Required;
            }

            return bldr.GetConnectionString(true);
        }
开发者ID:rcanright,项目名称:pgina,代码行数:27,代码来源:Configuration.cs


注:本文中的MySql.Data.MySqlClient.MySqlConnectionStringBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。