środa, 28 października 2009

Funkcja sprawdzająca czy polecenie DBCheckDB nie zwraca błedów


function BOOL DBCheckDB (sSQL, sServerName, sDBName, sDriver, bTrustedConn, sUserName, sUserPwd, bLog, szError)
OBJECT objConn, pADORecordSetObj, adoCommand;
STRING sTekst, sConnString;
STRING szADOConnObjID,szADORecordSetObjID;
number nPos;
BOOL bReturn;
begin
bReturn = FALSE;

// Create the connectionstring
if (sDriver == "") then
sConnString = "Provider=sqloledb;";
else
sConnString = "Driver={" + sDriver + "};";
endif;

if (bTrustedConn) then
//ACA_Log_AppendLine(" using Windows Authentication");
sConnString = sConnString + "server=" + sServerName + ";";
sConnString = sConnString + "database=" + sDBName + ";";
sConnString = sConnString + "Trusted_connection=Yes";
else
//ACA_Log_AppendLine(" using SQL Login");
sConnString = sConnString + "server=" + sServerName + ";";
sConnString = sConnString + "uid=" + sUserName + ";";
sConnString = sConnString + "pwd=" + sUserPwd + ";";
sConnString = sConnString + "database=" + sDBName;
endif;

try
szADOConnObjID = "ADODB.Connection";
set objConn = CreateObject(szADOConnObjID);

if (IsObject(objConn)) then

objConn.ConnectionString = sConnString;
objConn.CommandTimeout = 999999;
objConn.Open;

szADORecordSetObjID = "ADODB.Recordset";
set pADORecordSetObj = CreateObject(szADORecordSetObjID);
pADORecordSetObj.CursorType = 3;
pADORecordSetObj.ActiveConnection = objConn;
pADORecordSetObj.Open(sSQL);
if ((pADORecordSetObj.RecordCount >= 1)||(pADORecordSetObj.RecordCount = -1)) then
while (!pADORecordSetObj.EOF)
szError = pADORecordSetObj(3);
pADORecordSetObj.MoveNext;
endwhile;

if ((StrFind(szError,"found 0 allocation")>0)&&(StrFind(szError,"and 0 consistency")>0)) then
bReturn = TRUE;
else
bReturn = FALSE;
endif;
else
bReturn = FALSE;
endif;

else
if (bLog) then WriteLog(1,"Nie moża utworzyć obiektu połączenia ADODB.Connection do "+sDBName); endif;
endif;

set pADORecordSetObj = NOTHING;
set objConn = NOTHING;


catch
if (bLog) then WriteLog(1,"Błąd wykonania zapytania SQL"); endif;
endcatch;

return (bReturn);

end;

Brak komentarzy:

Prześlij komentarz