wtorek, 27 października 2009

Pobranie ścieżki danych serwera MSSQL

Jeżeli funkcja zwróci TRUE to do zmiennej svPath - zostanie przekazana ścieżka
function BOOL GetMSSQLPath(sServerName, sDBName, svPath, sDriver, bTrustedConn, sUserName, sUserPwd)
 OBJECT objConn, objRST;     
 STRING  szADOConnObjID;
 STRING sTekst, sConnString, sDBFileName;
 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;
 
  szADOConnObjID = "ADODB.Connection";
     set objConn = CreateObject(szADOConnObjID);         
 
        if (IsObject(objConn)) then 
  
   objConn.ConnectionString = sConnString;
   objConn.Open;        
   
   set objRST = objConn.Execute("select filename from sysfiles where filename like '%.mdf%' ");
   sDBFileName = objRST("filename");                                           
   ParsePath ( svPath, sDBFileName, PATH );       
   if (StrFind(svPath,"data\\")>0) then
    StrSub(svPath,svPath,0,StrFind(svPath,"data\\"));
   endif;                                        
   
   objConn.Close;   
   bReturn  = TRUE;   
     
  endif;
  
  set objConn = NOTHING;
  set objRST  = NOTHING;
  
 return (bReturn); 
end;

Brak komentarzy:

Prześlij komentarz