forked from uknowsec/SharpSQLTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBatch.cs
More file actions
69 lines (65 loc) · 2.01 KB
/
Batch.cs
File metadata and controls
69 lines (65 loc) · 2.01 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
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
namespace SharpSQLTools
{
class Batch
{
public static string RemoteExec(SqlConnection Conn, String Command, Boolean Flag)
{
String value = String.Empty;
try
{
//TODO:发送Command命令
SqlCommand cmd = new SqlCommand();
cmd.Connection = Conn;
//查询数据记录
cmd.CommandText = Command;
cmd.CommandType = CommandType.Text;
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
if (Flag)
{
value += String.Format("\r\n{0}", reader[0].ToString());
}
else
{
value = reader[0].ToString();
}
}
}
return value;
}
catch (Exception ex)
{
//Conn.Close();
Console.WriteLine("[!] Error log: \r\n" + ex.Message);
}
return null;
}
public static void CLRExec(SqlConnection Conn, String Command)
{
try
{
//TODO:发送Command命令
SqlCommand cmd = new SqlCommand();
cmd.Connection = Conn;
//查询数据记录
cmd.CommandText = Command;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
//Conn.Close();
Console.WriteLine("[!] Error log: \r\n" + ex.Message);
}
}
}
}