private static void StringBuilderCopy(DbConStringBuilder strBuilder, MySqlConnectionStringBuilder stringBuilder) { stringBuilder.Server = strBuilder.Server; stringBuilder.UserID = strBuilder.UserID; stringBuilder.Password = strBuilder.Password; stringBuilder.Database = strBuilder.Database; }
public static void CreateNewDatabase(string kindOfDatabase,DbConStringBuilder strBuilder) { //if else here MySqlConnectionStringBuilder stringBuilder = new MySqlConnectionStringBuilder(); StringBuilderCopy(strBuilder, stringBuilder); instance = new MySqlDatabase(stringBuilder.ConnectionString + ';' + "charset = utf8;"); instance2 = new MySqlDatabase(stringBuilder.ConnectionString + ';' + "charset = utf8;"); }
public static string stringConnection; //= "Server =.\\SQLEXPRESS ; Database=Clinic;Integrated Security = true"; #endregion Fields #region Methods //public static void InitSqlConnection(string passSql,string IPAddress) //{ // MySqlConnectionStringBuilder strBuilder = new MySqlConnectionStringBuilder(); // strBuilder.Server = IPAddress==" . . ."?"localhost":IPAddress; // strBuilder.UserID="root"; // strBuilder.Password = passSql; // strBuilder.Database="clinic"; // conn = new MySqlConnection(strBuilder.ConnectionString); //} private static DbConStringBuilder GetConnectionString(string passSql, string IPAddress) { DbConStringBuilder strBuilder = new DbConStringBuilder(); strBuilder.Server = IPAddress == "..." ? "127.0.0.1" : IPAddress; strBuilder.UserID = "root"; strBuilder.Password = passSql; strBuilder.Database = "clinic"; return strBuilder; }
public static void CreateNewDatabase(string kindOfDatabase, DbConStringBuilder strBuilder) { //if else here MySqlConnectionStringBuilder stringBuilder = new MySqlConnectionStringBuilder(); StringBuilderCopy(strBuilder, stringBuilder); instance = new MySqlDatabase(stringBuilder.ConnectionString + ';' + "charset = utf8;"); instance2 = new MySqlDatabase(stringBuilder.ConnectionString + ';' + "charset = utf8;"); instance3 = new MySqlDatabase(stringBuilder.ConnectionString + ';' + "charset = utf8;"); }
private void button1_Click(object sender, EventArgs e) { string IP = maskedTextBox1.Text.Trim(); IP = Regex.Replace(IP, @"\s", ""); string[] lines = { textBox1.Text, IP }; // WriteAllLines creates a file, writes a collection of strings to the file, // and then closes the file. System.IO.File.WriteAllLines("WriteLines.txt", lines); File.SetAttributes( "WriteLines.txt", FileAttributes.Archive | FileAttributes.Hidden ); //test connection ; try { if (checkBox1.Checked == false) { ///Old structure DbConStringBuilder strBuilder = new DbConStringBuilder(); strBuilder.Server = "localhost"; strBuilder.UserID = "root"; strBuilder.Password = textBox1.Text; //Program.conn = new MySqlConnection(strBuilder.ConnectionString); //Program.conn.Open(); //InitDatabase(Program.conn, textBox1.Text); ///New Structure /// DatabaseFactory.CreateNewDatabase("", strBuilder); IDatabase database = DatabaseFactory.Instance; database.CreateDatabase(textBox1.Text); } else { DbConStringBuilder strBuilder = new DbConStringBuilder(); strBuilder.Server = IP == " . . ." ? "localhost" : IP; strBuilder.UserID = "root"; strBuilder.Password = textBox1.Text; DatabaseFactory.CreateNewDatabase("", strBuilder); IDatabase database = DatabaseFactory.Instance; } } catch (Exception ex) { MessageBox.Show("Kết nối SQl server thất bại , vui lòng thử lại !"+ex.Message); File.Delete("WriteLines.txt"); return; } this.DialogResult = DialogResult.OK; }