프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / DataBaseCreate / Program.cs @ d8bd4799

이력 | 보기 | 이력해설 | 다운로드 (1.6 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Data.SqlClient;
4
using System.IO;
5
using System.Linq;
6
using System.Text;
7
using System.Threading.Tasks;
8

    
9
namespace DataBaseCreate
10
{
11
    class Program
12
    {
13
        static void Main(string[] args)
14
        {
15
            foreach (var item in args)
16
            {
17
                RunSql(item);
18
            }
19

    
20
            Console.ReadKey();
21
        }
22

    
23
        static void RunSql(string filePath)
24
        {
25
            string connectionString = Properties.Settings.Default.ID2Manager; // 데이터베이스 연결 문자열 입력
26

    
27
            string sqlContent = File.ReadAllText(filePath);
28

    
29
            using (SqlConnection connection = new SqlConnection(connectionString))
30
            {
31
                connection.Open();
32
                string[] sqlCommands = sqlContent.Split(new[] { "GO" }, StringSplitOptions.RemoveEmptyEntries);
33

    
34
                foreach (string sqlCommand in sqlCommands)
35
                {
36
                    using (SqlCommand command = new SqlCommand(sqlCommand, connection))
37
                    {
38
                        try
39
                        {
40
                            command.ExecuteNonQuery();
41
                            Console.WriteLine("SQL command executed successfully.");
42
                        }
43
                        catch (Exception ex)
44
                        {
45
                            Console.WriteLine("Error executing SQL command: " + ex.Message);
46
                        }
47
                    }
48
                }
49

    
50

    
51
                Console.WriteLine($"{filePath} file executed successfully.");
52
            }
53
        }
54

    
55
    }
56
}
클립보드 이미지 추가 (최대 크기: 500 MB)