My system is Windows 10 64Bit, MS-SQL Server 2012 Express 64Bit.
I sometimes get error at the time of first connection to my db server. Moreover, some of the customers also having exact same problem. One of them using Windows 10 64Bit, MS-SQL Server 2014 Express 64bit.
I could not find a pattern to figure source of the problem. Google searches were not helpful.
My application use below code to connect to db:
Code: Select all
procedure ReadDatabaseSettingsFromIni(const DB: TUniConnection; const IniSectionName, BaseDirectory: string; AutoOpen: Boolean = True);
var
Ini: TIniFile;
TempString: string;
begin
if not DirectoryExists(IncludeTrailingPathDelimiter(BaseDirectory)) then Exit();
Ini := TIniFile.Create(IncludeTrailingPathDelimiter(BaseDirectory) + ININAME);
try
DB.Close();
DB.ProviderName := 'SQL Server';
DB.Server := Ini.ReadString(IniSectionName, 'Server', EmptyStr);
DB.Port := Ini.ReadInteger(IniSectionName, 'Port', 0);
TempString := Ini.ReadString(IniSectionName, 'User', EmptyStr);
if TempString = EmptyStr then Exit();
try
TempString := DecryptItAES(TempString, string(KeyDB));
except
Exit(); // Someone messed with encrypted information
end;
DB.Username := TempString;
TempString := Ini.ReadString(IniSectionName, 'Pass', EmptyStr);
if TempString = EmptyStr then Exit();
try
TempString := DecryptItAES(TempString, string(KeyDB));
except
Exit(); // Someone messed with encrypted information
end;
DB.Password := TempString;
DB.Database := Ini.ReadString(IniSectionName, 'Database', EmptyStr);
finally
Ini.Free();
end;
DB.SpecificOptions.Values['Provider'] := 'prDirect';
DB.LoginPrompt := False;
if AutoOpen then
begin
try
DB.Open();
except
on E:EUniError do
begin
TempString := 'Error connecting to database.' + sLineBreak +
'Server: ' + DB.Server + ':' + DB.Port.ToString + sLineBreak +
'Database: ' + DB.Database + sLineBreak +
'Error: ' + FormatFloat('(0) ', E.ErrorCode) + E.Message;
Log(TempString, BaseDirectory);
TErrorBox.Show(TempString);
end;
end;
end;
end;
Code: Select all
2016-11-19 22:05:25.002 Error connecting to database. Server: localhost:0 Database: sarel Error: (0) Socket error on reading
2016-11-20 12:28:37.546 Error connecting to database. Server: localhost:0 Database: sarel Error: (0) Socket error on reading
2016-11-20 17:09:57.747 Error connecting to database. Server: localhost:0 Database: sarel Error: (0) Socket error on reading
2016-11-20 21:53:38.022 Error connecting to database. Server: localhost:0 Database: sarel Error: (0) Socket error on reading
Thanks.