private void ConnectSQLite() { try { var connectString = "Data Source=dbdemos.db3"; SQLiteConnection sQLiteConnection = new SQLiteConnection(connectString); sQLiteConnection.Open(); if (sQLiteConnection.State == ConnectionState.Open) { MessageBox.Show("测试连接成功!"); string file = Application.ExecutablePath; file = Path.GetDirectoryName(file) + "/config.txt"; if (File.Exists(file)) { File.Delete(file); } ConfigFileUtil <ConfigItem> .SaveToFile(GlobalConfig.Item, file); this.btnNext.Enabled = true; } else { } sQLiteConnection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSaveConfig_Click(object sender, EventArgs e) { try { this.RefreshConfig(); #region 保存配置到config.txt文件中 string file = Application.ExecutablePath; file = Path.GetDirectoryName(file) + "/config.txt"; if (File.Exists(file)) { File.Delete(file); } ConfigFileUtil <ConfigItem> .SaveToFile(GlobalConfig.Item, file); #endregion } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 测试连接的方法 /// </summary> private void ConnectSQLServer() { try { string constr = "Server={0};Database={1};uid={2};pwd={3}"; constr = String.Format(constr, GlobalConfig.Item.Server, GlobalConfig.Item.DataBase, GlobalConfig.Item.UID, GlobalConfig.Item.PWD); SqlConnection con = new SqlConnection(constr); con.Open(); bool flag = false; if (con.State == ConnectionState.Open) { flag = true; } con.Close(); if (flag) { MessageBox.Show("测试连接成功!"); string file = Application.ExecutablePath; file = Path.GetDirectoryName(file) + "/config.txt"; if (File.Exists(file)) { File.Delete(file); } ConfigFileUtil <ConfigItem> .SaveToFile(GlobalConfig.Item, file); this.btnNext.Enabled = true; } else { MessageBox.Show("测试连接失败!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }