我使用ado連接到inno的connect to sql 2008,我想知道我們是否可以將詳細信息記錄到文件中,以便可以捕獲sql引發的錯誤。如何記錄ADO連接的執行語句
注:直通ADO連接,我不只是執行select querys,我使用ADO連接執行設置語句來創建數據庫,程序,表格等
我使用ado連接到inno的connect to sql 2008,我想知道我們是否可以將詳細信息記錄到文件中,以便可以捕獲sql引發的錯誤。如何記錄ADO連接的執行語句
注:直通ADO連接,我不只是執行select querys,我使用ADO連接執行設置語句來創建數據庫,程序,表格等
用於記錄數據庫供應商特定錯誤,請使用Errors
收集的ADO Connection
對象。如何將這些錯誤記錄到文件中,顯示以下僞腳本:
procedure ConnectButtonClick(Sender: TObject);
var
I: Integer;
ADOError: Variant;
ADOConnection: Variant;
ErrorLog: TStringList;
begin
ErrorLog := TStringList.Create;
try
try
ADOConnection := CreateOleObject('ADODB.Connection');
// open the connection and work with your ADO objects using this
// connection object; the following "except" block is the common
// error handler for all those ADO objects
except
// InnoSetup scripting doesn't support access to the "Exception"
// object class, so now you need to distinguish, what caused the
// error (if ADO or something else); for this is here checked if
// the ADO connection object is created and if so, if its Errors
// collection is empty; if it's not, or the Errors collection is
// empty, then the exception was caused by something else than a
// database provider
if VarIsEmpty(ADOConnection) or (ADOConnection.Errors.Count = 0) then
MsgBox(GetExceptionMessage, mbCriticalError, MB_OK)
else
// the Errors collection of the ADO connection object contains
// at least one Error object, but there might be more of them,
// so iterate the collection and for every single Error object
// add the line to the logging string list
for I := 0 to ADOConnection.Errors.Count - 1 do
begin
ADOError := ADOConnection.Errors.Item(I);
ErrorLog.Add(
'Error no.: ' + IntToStr(ADOError.Number) + '; ' +
'Source: ' + ADOError.Source + '; ' +
'Description: ' + ADOError.Description
);
end;
end;
finally
ErrorLog.SaveToFile('c:\LogFile.txt');
ErrorLog.Free;
end;
end;
是不是指如何記錄ADO提供程序特定的錯誤?腳本執行期間發生的所有錯誤都可能由異常處理程序捕獲,但您可以從連接對象提供程序獲取特定(更詳細)的錯誤對象。那是你要的嗎 ? – TLama
是的,謝謝Tlama。 – anand