-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
63 lines (62 loc) · 2.41 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
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FinancialCrm
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
bool isConnected = IsConnectionCorrect();
if (isConnected)
{
Application.Run(new LoginForm());
}
else
{
Application.Run(new ConfigurationForm());
}
//Application.Run(new TestForm());
}
static bool IsConnectionCorrect()
{
string defaultConnectionString = $"data source={Properties.Settings.Default.DataSource};" +
$"initial catalog={Properties.Settings.Default.InitialCatalog};" +
$"integrated security={Properties.Settings.Default.IntegratedSecurity};" +
$"user id={Properties.Settings.Default.UserId};" +
$"password={Properties.Settings.Default.Password};" +
"trustservercertificate=True;MultipleActiveResultSets=True;App=EntityFramework";
try
{
// Bağlantıyı kontrol et
using (var connection = new SqlConnection(defaultConnectionString))
{
connection.Open(); // Bağlantıyı açmayı dener
}
return true; // Başarılı
}
catch (SqlException ex)
{
MessageBox.Show($"SQL hatası: {ex.Message}", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (InvalidOperationException ex)
{
MessageBox.Show($"Bağlantı hatası: {ex.Message}", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show($"Bilinmeyen bir hata: {ex.Message}", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return false;
}
}
}