-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
executable file
·46 lines (44 loc) · 1.38 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
using System;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
while (true)
{
try
{
SqlConnectionStringBuilder connbuilder = new SqlConnectionStringBuilder();
connbuilder.DataSource = "10.0.0.20";
connbuilder.UserID = "sa";
connbuilder.Password = "Yukon900";
connbuilder.InitialCatalog = "master";
using (SqlConnection connection = new SqlConnection(connbuilder.ConnectionString))
{
Console.WriteLine("Connecting");
connection.Open();
Console.WriteLine("Connected");
String sql = "SELECT CONVERT(sysname,SERVERPROPERTY('ServerName'))";
using (SqlCommand command = new SqlCommand(sql,connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine(reader.GetString(0));
}
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Lost connection");
}
}
}
}
}