私はado接続を使用してinnoからsql2008に接続していますが、sqlによってスローされたエラーをキャプチャできるように、詳細をファイルに記録できるかどうかを知りたいです。
注:ado接続を使用して、selectクエリを実行するだけでなく、ado接続を使用して一連のステートメントを実行し、データベース、プロシージャ、テーブルなどを作成しています。
私はado接続を使用してinnoからsql2008に接続していますが、sqlによってスローされたエラーをキャプチャできるように、詳細をファイルに記録できるかどうかを知りたいです。
注:ado接続を使用して、selectクエリを実行するだけでなく、ado接続を使用して一連のステートメントを実行し、データベース、プロシージャ、テーブルなどを作成しています。
データベースプロバイダー固有のエラーをログに記録するErrors
には、ADOConnection
オブジェクトのコレクションを使用します。これらのエラーをファイルに記録する方法は、次の疑似スクリプトを示しています。
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;