Kodun Doğru Hali
var ConfigList : TClStringList; ConfigPath : String; WatchdogTimer : TClTimer; IsChecking : Boolean; InheritedForm : TclForm; CheckQuery : TClSqlQuery;
void InitForm(AForm : TclForm); { InheritedForm = AForm; }
void InitConfig; { try ConfigPath = Clomosy.AppFilesPath + 'db_config.txt'; if (ConfigList == nil) { ConfigList = Clomosy.StringListNew; } if (clFileExists('db_config.txt', Clomosy.AppFilesPath)) { ConfigList.Text = clLoadFromFile(ConfigPath); } except ShowMessage('InitConfig Exception: ' + LastExceptionMessage); } }
void SaveDBConnection(AHost, AUser, APass, ADBName : String; APort: Integer); { try if (ConfigList == nil) { ConfigList = Clomosy.StringListNew; } ConfigList.Clear; ConfigList.Add('Host=' + AHost); ConfigList.Add('User=' + AUser); ConfigList.Add('Pass=' + APass); ConfigList.Add('DB=' + ADBName); ConfigList.Add('Port=' + IntToStr(APort)); clSaveToFile(ConfigPath, ConfigList.Text); ShowMessage('Database configuration saved successfully.'); except ShowMessage('SaveDBConnection Exception: ' + LastExceptionMessage); } }
void OnHealthTimeout; { if (IsChecking == True) { IsChecking = False; WatchdogTimer.Enabled = False; ShowMessage('Connection Timeout: Server 5 saniye içinde cevap vermedi.'); } }
void SetupTimer; { if ((WatchdogTimer == nil) && (InheritedForm <> nil)) { WatchdogTimer = InheritedForm.AddNewTimer(InheritedForm, 'WatchdogTimer', 5000); WatchdogTimer.Enabled = False; InheritedForm.AddNewEvent(WatchdogTimer, tbeOnTimer, 'OnHealthTimeout'); } }
function CheckDatabaseHealth(AHost, AUser, APass, ADBName : String; APort: Integer): Boolean; { try Result = False; SetupTimer; if (WatchdogTimer == nil) { ShowMessage('Hata: Timer başlatılamadı. InitForm çağrıldığından emin olun.'); exit; }
IsChecking = True; WatchdogTimer.Interval = 5000; WatchdogTimer.Enabled = True;
// Step 1: Connectivity Check Clomosy.DBSQLServerConnect('SQL Server', AHost, AUser, APass, ADBName, APort); // Step 2: Lazy Initialization of Query CheckQuery = Clomosy.DBSQLServerQuery; CheckQuery.SQL.Text = 'SELECT DB_ID(' + QuotedStr(ADBName) + ') as db_found'; CheckQuery.Open; if (IsChecking == True) { IsChecking = False; WatchdogTimer.Enabled = False;
if (CheckQuery.FieldByName('db_found').AsString == '') { ShowMessage('Hata: Database bulunamadı.'); Result = False; } else { Clomosy.DBSQLServerConnect('SQL Server', AHost, AUser, APass, ADBName, APort); Result = True; } } except IsChecking = False; if (WatchdogTimer <> nil) { WatchdogTimer.Enabled = False; } ShowMessage('Bağlantı Hatası: ' + LastExceptionMessage); Result = False; } }
function LoadAndConnect: Boolean; var vHost, vUser, vPass, vDB : String; vPort : Integer; { InitConfig; try Result = False; if (ConfigList.Count > 0) { vHost = ConfigList.Values['Host']; vUser = ConfigList.Values['User']; vPass = ConfigList.Values['Pass']; vDB = ConfigList.Values['DB']; if (ConfigList.Values['Port'] == '') { vPort = 1433; } else { vPort = StrToInt(ConfigList.Values['Port']); } Result = CheckDatabaseHealth(vHost, vUser, vPass, vDB, vPort); } else { ShowMessage('Ayarlar bulunamadı.'); Result = False; } except ShowMessage('LoadAndConnect Exception: ' + LastExceptionMessage); Result = False; } } {
WatchdogTimer = nil; }
https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" rel="nofollow - https://static.cloudflareinsights.com/beacon.min.js/vcd15cbe7772f49c399c6a5babf22c1241717689176015" integrity="sha512-ZpsOmlRQV6y907TI0dKBHq9Md29nnaEIPlkf84rnaERnq6zvWvPUqr2ft8M1aS28oN72PdrCzSjY4U6VaAw1EQ==" data-cf-beacon="{"version":"2024.11.0","token":"439455f3e46c40b98dbd42a2f1a954d8","r":1,"server_timing":{"name":{"cfCacheStatus":true,"cfEdge":true,"cfExtPri":true,"cfL4":true,"cfOrigin":true,"cfSpeedBrain":true},"location_startswith":null}}" crossorigin="anonymous">
|