Microsoft KB Archive/164970

From BetaArchive Wiki

BUG: Disk Dumps May Cause Handled AV When Space Is Low

Q164970



The information in this article applies to:


  • Microsoft SQL Server version 6.0





SYMPTOMS

Under rare circumstances, if the amount of available disk space is very low, SQL Server may generate a handled access violation (AV) when trying to dump to disk.




WORKAROUND

Make sure that there is an adequate amount of free space before dumping to the disk, or dump to a different type of dump device. Sample code is provided in the MORE INFORMATION section of this article for an extended stored procedure that you can use to determine the amount of free space before dumping to disk.



STATUS

Microsoft has confirmed this to be a problem in Microsoft SQL Server version 6.0. This problem has been corrected in Microsoft SQL Server version 6.5.



MORE INFORMATION

To assist in checking for necessary disk space before performing an automated backup, you can use an extended stored procedure to determine the amount of available disk space on the server. The documentation provides a sample procedure, xp_diskfree, that provides this capability. The following sample is similar to that function, but allows UNC drive specifications and returns the result as an output parameter rather than a result set.

If the code were compiled into a procedure called xp_sample, the usage would be:


    declare @freespace int
    exec xp_sample '\\server1\share1\', @freespace output
    select @freespace 


      • THE FOLLOWING CODE IS FOR SAMPLE USE ONLY ***


   #define MAX_SRVINT4_VALUE 2147483647
      DBINT paramlength;
      DBCHAR rootname[_MAX_PATH];
      DBCHAR bErrorMsg[2 * _MAX_PATH];
      DWORD secPerCluster;
      DWORD bytesPerSector;
      DWORD freeClusters;
      DWORD totalClusters;
      DBINT space_remaining;
      __int64 large_calc;

      //Make sure they specified drive and output param for space
      if (srv_rpcparams(srvproc) < 2)
      {
         sprintf(bErrorMsg, "SYNTAX:\nDECLARE @freespace int\nexec
         xp_sample '<path>', "  \ 
         "@freespace OUTPUT\n\nwhere <path> is like
         \\\\<machine>\\<share>\\ or <drive>:\\");
         srv_sendmsg(srvproc, SRV_MSG_ERROR, CMDSHELL_ERROR, SRV_INFO,
         (DBTINYINT)0, NULL, 0, 0, bErrorMsg, SRV_NULLTERM);
         srv_senddone(srvproc, (SRV_DONE_ERROR | SRV_DONE_MORE), 0, 0);
         return(XP_ERROR);
      }

      //Move the path specified into rootname
      paramlength = srv_paramlen(srvproc, 1);
      srv_bmove(srv_paramdata(srvproc, 1), rootname, paramlength);
      rootname[paramlength] = '\0'; //NULL terminate

      if (GetDiskFreeSpace(rootname, &secPerCluster,
            &bytesPerSector, &freeClusters, &totalClusters))
      {
          large_calc = secPerCluster * freeClusters * bytesPerSector;
      }
      else
      {
         sprintf(bErrorMsg, "GetDiskFreeSpace failed with error %d "  \ 
            "on path %s", GetLastError(), rootname);
         srv_sendmsg(srvproc, SRV_MSG_ERROR, CMDSHELL_ERROR, SRV_INFO,
            (DBTINYINT)0, NULL, 0, 0, bErrorMsg, SRV_NULLTERM);

         srv_senddone(srvproc, (SRV_DONE_ERROR | SRV_DONE_MORE), 0, 0);
         return(XP_ERROR);
      }

      //If we exceed 2 GB of disk space, return 2 GB free as this is
      //the largest value we can pass back to an INT value
      if (large_calc > MAX_SRVINT4_VALUE)
      {
         large_calc = MAX_SRVINT4_VALUE;
      }
      space_remaining = (DBINT)large_calc;

      //Return the size in the output param
      srv_paramset(srvproc, 2, (BYTE *)&space_remaining, 4);
      srv_senddone(srvproc, SRV_DONE_MORE, 0, 0);
      return(XP_NOERROR); 


See the Programming Open Data Services documentation for further information on writing and registering extended stored procedures.

Additional query words: hard

Keywords : kbprogramming
Issue type : kbbug
Technology : kbSQLServSearch kbAudDeveloper kbSQLServ600


Last Reviewed: April 11, 1999
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.