-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqlQuery.cs
55 lines (50 loc) · 1.46 KB
/
sqlQuery.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
54
55
using System;
using System.Data.SqlClient;
namespace SQLQuery
{
internal class Program
{
static SqlConnection authenticate(string sqlServer)
{
string conString = String.Format("Server = {0}; Database = master; Integrated Security = True;", sqlServer);
SqlConnection con = new SqlConnection(conString);
try
{
con.Open();
Console.WriteLine("[+] Auth Success!");
}
catch
{
con.Close();
Console.WriteLine("[-] Auth Failed.");
Environment.Exit(0);
}
return con;
}
static void executeQuery(SqlConnection con, string queryStr)
{
SqlCommand command = new SqlCommand(queryStr, con);
try
{
SqlDataReader reader = command.ExecuteReader();
while (reader.Read() == true)
{
Console.WriteLine("[+] " + reader[0]);
}
reader.Close();
con.Close();
}
catch
{
con.Close();
Console.WriteLine("[-] Command Execution Failed.");
Environment.Exit(0);
}
}
static void Main(string[] args)
{
SqlConnection con = authenticate(args[0]);
executeQuery(con, args[1]);
}
}
}