-
Notifications
You must be signed in to change notification settings - Fork 11
/
Program.cs
executable file
·66 lines (60 loc) · 2.21 KB
/
Program.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
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlClient
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 5)
{
Console.WriteLine("[*]ERROR: Please provide the correct number of arguments!");
Console.WriteLine("[*]Ex: SqlClient.exe <username> <password> <IP Address> <databasename> <SQL Query>");
return;
}
string connString = @"Server=" + args[2] + ";Database=" + args[3] + ";User ID=" + args[0] + ";Password=" + args[1];
try
{
using (SqlConnection conn = new SqlConnection(connString))
{
//retrieve the SQL Server instance version
string query = args[4];
SqlCommand cmd = new SqlCommand(query, conn);
//open connection
conn.Open();
//execute the SQLCommand
SqlDataReader dr = cmd.ExecuteReader();
//check if there are records
if (dr.HasRows)
{
while (dr.Read())
{
//display retrieved record (first column only/string value)
for (int i = 0; i < dr.FieldCount; i++)
{
Console.WriteLine(dr.GetName(i));
}
for (int i = 0; i < dr.FieldCount; i++)
{
Console.WriteLine(dr.GetValue(i));
}
}
}
else
{
Console.WriteLine("No data found.");
}
dr.Close();
}
}
catch (Exception ex)
{
//display error message
Console.WriteLine("Exception: " + ex.Message);
}
}
}
}