-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlManagerForm.cs
More file actions
88 lines (77 loc) · 2.62 KB
/
SqlManagerForm.cs
File metadata and controls
88 lines (77 loc) · 2.62 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace Spiffdog.SqlLocalDbManager
{
public partial class Form1 : Form
{
FileDialog _dialog;
public Form1()
{
InitializeComponent();
}
private void btnCreate_Click(object sender, EventArgs e)
{
DoProcess("create");
}
private void btnStart_Click(object sender, EventArgs e)
{
DoProcess("start");
}
private void btnStop_Click(object sender, EventArgs e)
{
DoProcess("stop");
}
private void btnDelete_Click(object sender, EventArgs e)
{
DoProcess("delete");
}
private void btnGetInfo_Click(object sender, EventArgs e)
{
DoProcess("info");
}
private void DoProcess(string activity)
{
try
{
if (string.IsNullOrEmpty(Global.SqlLocalDbPath))
{
_dialog = new OpenFileDialog();
_dialog.Title = "Locate SqlLocalDB.exe";
_dialog.FileName = "SqlLocalDB.exe";
_dialog.Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*";
_dialog.InitialDirectory = Global.SqlLocalDbDefaultPath;
_dialog.FilterIndex = 1;
if (_dialog.ShowDialog() == DialogResult.OK)
{
Global.SqlLocalDbPath = "\"" + _dialog.FileName + "\"";
}
}
var info = new ProcessStartInfo(Global.SqlLocalDbPath, " " + activity + " " + txtInstanceName.Text);
var p = new Process();
p.StartInfo = info;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.WaitForExit();
var reader = p.StandardOutput;
var output = reader.ReadToEnd();
reader.Close();
if (output.Length == 0)
{
reader = p.StandardError;
var error = reader.ReadToEnd();
reader.Close();
txtResult.Text = error;
} else {
txtResult.Text = output;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}