-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBConnection.cs
53 lines (46 loc) · 1.35 KB
/
DBConnection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.IO;
using System.Windows.Forms;
namespace SQLGenerator
{
public partial class DBConnection : Form
{
string TxtFilePath
{
get
{
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Cache.txt");
}
}
public DBConnection()
{
InitializeComponent();
}
private void btnConnect_Click(object sender, EventArgs e)
{
string conStr = tbConStr.Text.Trim();
SQLHelper helper = new SQLHelper(conStr);
try
{
helper.OpenDB();
MainForm.DBConString = conStr;
MainForm.DBInfo = $"当前数据库信息:服务器【{helper.SqlConnection.DataSource}】,数据库【{helper.SqlConnection.Database}】";
CommonHelper.SaveTxt(TxtFilePath, conStr);
this.DialogResult = DialogResult.OK;
this.Close();
}
catch(Exception ex)
{
MessageBox.Show("连接失败,请重试");
}
finally
{
helper.CloseDB();
}
}
private void DBConnection_Load(object sender, EventArgs e)
{
tbConStr.Text = CommonHelper.ReadTxt(TxtFilePath);
}
}
}