-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (61 loc) · 2.69 KB
/
Program.cs
File metadata and controls
65 lines (61 loc) · 2.69 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
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
namespace Container.DBTester
{
class Program
{
static void Main(string[] args)
{
if (args.Length <= 1)
{
Console.WriteLine("Please run again with the connection string supplied and the table you wish the query. \n Example\tContainer.DBTester.exe 'my stringy connection string of stringliness' 'My Table of tables'"); //Check for connection string and table
}
else
{
try
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.ConnectionString=args[0];
using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
{
List<string> queryResp = new List<string>();
Console.WriteLine($"Container SQL Query Tester \t{connection.DataSource} \n");
Console.Write($"Attempting connection\n");
DateTime startTime = DateTime.Now;
connection.Open();
if (connection.State.ToString() == "Open")
{
Console.WriteLine($"\tConnection established");
}
StringBuilder sb = new StringBuilder();
sb.Append("SELECT TOP (100) [Name]");
sb.Append($"FROM {args[1]}");
String sql = sb.ToString();
using (SqlCommand command = new SqlCommand(sql, connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
//Console.WriteLine("{0}", reader.GetString(0));
queryResp.Add(reader.GetString(0));
}
}
}
DateTime endTime = DateTime.Now;
TimeSpan interval = endTime - startTime;
Console.WriteLine($"\tQuery Completed");
Console.WriteLine("\nQuery Statistics");
Console.WriteLine($"\t{queryResp.Count} rows\n\t{interval.Milliseconds}ms from {args[1]}");
}
}
catch (SqlException e)
{
Console.WriteLine(e.ToString());
}
}
}
}
}