FIX: The Osql.exe utility does not run a Transact-SQL script completely if you start the program from a remote session by using a background service and then log off the console session

This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 471423 (SQL Server 8.0)
Microsoft distributes Microsoft SQL Server 2000 hotfixes as one downloadable file. Because the hotfixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2000 hotfix release.
After you start the osql utility (Osql.exe) by using a background service like the SQL Server Agent or the Microsoft Windows Task Scheduler, if a user logs off from the console session on the computer, you may notice that the osql utility stops and does not completely run the Transact-SQL script that is passed to the osql utility. Even though the osql utility stops without completely running the Transact-SQL script, the background service indicates that the job was successful. For example, the SQL Server Agent displays the status as Succeeded.
When a user logs off from the console session of the computer, the operating system sends the CTRL_LOGOFF_EVENT message to the osql utility. The osql utility processes this message as if the osql utility is run interactively in the console session of the computer. Therefore, the process stops.

Service pack information

To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
290211 How to obtain the latest SQL Server 2000 service pack

Hotfix information

The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
   Date         Time   Version        Size       File name   ------------------------------------------------------------------   19-Jun-2004  02:44  2000.80.954.0    664,128  Autoplt.dll         19-Jun-2004  02:44  2000.80.954.0     78,400  Console.exe         19-Jun-2004  02:44  2000.80.954.0    315,968  Custtask.dll        19-Jun-2004  02:44  2000.80.954.0     33,340  Dbmslpcn.dll        08-Apr-2004  21:42                   786,432  Distmdl.ldf   08-Apr-2004  21:42                 2,359,296  Distmdl.mdf   10-Oct-2003  18:48                       180  Drop_repl_hotfix.sql   19-Jun-2004  02:44  2000.80.954.0  1,905,216  Dtspkg.dll          19-Jun-2004  02:44  2000.80.954.0    528,960  Dtspump.dll         19-Jun-2004  02:44  2000.80.954.0  1,557,052  Dtsui.dll           19-Jun-2004  02:44  2000.80.954.0    639,552  Dtswiz.dll          10-Oct-2003  18:48                   747,927  Instdist.sql   10-Oct-2003  18:48                     1,581  Inst_repl_hotfix.sql   19-Jun-2004  02:44  2000.80.954.0    352,828  Isqlw.exe           19-Jun-2004  02:44  2000.80.954.0     82,492  Itwiz.exe           19-Jun-2004  02:44  2000.80.954.0     90,692  Msgprox.dll         19-May-2004  23:43  8.11.40209.0     209,408  Mssdi98.dll         19-Jun-2004  02:44  2000.80.954.0     62,024  Odsole70.dll        19-Jun-2004  02:45  2000.80.954.0     25,144  Opends60.dll        19-Jun-2004  02:44  2000.80.954.0     57,904  Osql.exe            19-Jun-2004  02:44  2000.80.954.0    279,104  Pfutil80.dll        10-Oct-2003  18:37                   550,780  Procsyst.sql   08-Apr-2004  21:42                    12,305  Qfe469315.sql   08-Apr-2004  21:42                    19,195  Qfe469571.sql   17-Jun-2004  15:12                 1,105,167  Replmerg.sql   19-Jun-2004  02:44  2000.80.954.0    221,768  Replprov.dll        19-Jun-2004  02:44  2000.80.954.0    307,784  Replrec.dll         17-Jun-2004  02:37  2000.80.954.0    159,813  Replres.rll   10-Oct-2003  18:48                 1,087,150  Replsys.sql   10-Oct-2003  18:48                   986,603  Repltran.sql   19-Jun-2004  02:44  2000.80.954.0    287,304  Rinitcom.dll        19-Jun-2004  02:44  2000.80.954.0     78,416  Sdiclnt.dll         19-Jun-2004  02:44  2000.80.954.0     66,112  Semmap.dll          19-Jun-2004  02:44  2000.80.954.0     57,916  Semnt.dll           19-Jun-2004  02:44  2000.80.954.0    492,096  Semobj.dll          17-Jun-2004  03:14  2000.80.954.0    172,032  Semobj.rll   19-Jun-2004  02:44  2000.80.954.0     53,832  Snapshot.exe        12-Mar-2004  03:10                   117,834  Sp3_serv_uni.sql   19-Jun-2004  02:43  2000.80.954.0     28,672  Sqlagent.dll        19-Jun-2004  02:44  2000.80.954.0    311,872  Sqlagent.exe        19-Jun-2004  02:43  2000.80.954.0    168,001  Sqlakw32.dll        19-Jun-2004  02:44  2000.80.954.0     33,344  Sqlctr80.dll        19-Jun-2004  02:44  2000.80.954.0  4,215,360  Sqldmo.dll          19-Jun-2004  02:44                    25,172  Sqldumper.exe       17-Jun-2004  02:24  2000.80.954.0     28,672  Sqlevn70.rll   19-Jun-2004  02:44  2000.80.954.0    180,792  Sqlmap70.dll        19-Jun-2004  02:44  2000.80.954.0    188,992  Sqlmmc.dll          17-Jun-2004  03:22  2000.80.954.0    479,232  Sqlmmc.rll   19-Jun-2004  02:44  2000.80.954.0    401,984  Sqlqry.dll          19-Jun-2004  02:44  2000.80.954.0     57,920  Sqlrepss.dll        19-Jun-2004  02:44  2000.80.954.0  7,581,777  Sqlservr.exe        19-Jun-2004  02:44  2000.80.954.0    590,396  Sqlsort.dll         19-Jun-2004  02:44  2000.80.954.0     45,644  Sqlvdi.dll          19-Jun-2004  02:44  2000.80.954.0    106,588  Sqsrvres.dll        19-Jun-2004  02:44  2000.80.954.0     33,340  Ssmslpcn.dll        19-Jun-2004  02:44  2000.80.954.0     82,492  Ssnetlib.dll        19-Jun-2004  02:44  2000.80.954.0     25,148  Ssnmpn70.dll        19-Jun-2004  02:44  2000.80.954.0    123,456  Stardds.dll         19-Jun-2004  02:44  2000.80.954.0    158,240  Svrnetcn.dll        19-Jun-2004  02:44  2000.80.954.0     76,416  Svrnetcn.exe        19-Jun-2004  02:44  2000.80.954.0     49,228  Ums.dll             19-Jun-2004  02:44  2000.80.954.0     98,872  Xpweb70.dll      				
Note Because of file dependencies, the most recent hotfix that contains these files may also contain additional files.
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. This problem was first corrected in Microsoft SQL Server 2000 Service Pack 4.

Steps to reproduce the behavior

  1. Open a Terminal Server Client session of a computer.
  2. Start Notepad.
  3. In Notepad, write a Transact-SQL script that runs for a long time. For example, use the following Transact-SQL script that has an infinite loop:
    declare @variable intset @variable= 2while (@variable > 1)beginprint @variableset @variable= @variable + 1end
  4. Save the script as InstallationDrive\Test.sql.

    Note InstallationDrive is a placeholder for the default installation drive on the computer.
  5. In the Terminal Server Client session, start the osql utility by using one of the following methods:
    • Use Windows Task Scheduler
      1. In Control Panel, open Scheduled Tasks.
      2. On the File menu, point to New, and then click Scheduled Task.
      3. Double-click New Task to open the New Task dialog box.
      4. In the Run box, type the following command:
        "InstallationDrive:\Program Files\Microsoft SQL Server\80\Tools\Binn\Osql.exe" -E -i InstallationDrive:\Test.sql
        Note InstallationDrive is a placeholder for the default installation drive on the computer.
      5. In the Start in box, type InstallationDrive:\Program Files\Microsoft SQL Server\80\Tools\Binn.
      6. On the Schedule tab, change the schedule timings, and then click OK.
      7. In the Set Account Information dialog box, type the user account and the password of your logon account, and then click OK.
      8. Right-click the job that you created, and then click Run.
      9. While the scheduled task is running, log on to the console session, and then log off from the console session on the computer.
    • Use SQL Server Agent
      1. Start SQL Server Enterprise Manager.
      2. Expand the registered instance of a SQL Server.
      3. Under the server name, expand Management, and then expand SQL Server Agent.
      4. Under SQL Server Agent, right-click Jobs, and then click New Job.
      5. On the General tab, type a name for the job in the Name box.
      6. On the Steps tab, click New.
      7. On the General tab, type a name for the step in the Step name box.
      8. In the Type list, click Operating System Command (CmdExec).
      9. In the Command box, type "InstallationDrive:\Program Files\Microsoft SQL Server\80\Tools\Binn\Osql.exe" -E -i InstallationDrive:\Test.sql -o InstallationDrive:\Test.txt, and then click OK.

        Note InstallationDrive is a placeholder for the default installation drive on the computer.
      10. In the New Job Properties - SQLServerName dialog box, click OK.
      11. Right-click the job that you created, and then click Start Job.
      12. While the job is running, log on to the console session, and then log off from the console session on the computer.
    You notice that the scheduled task or the SQL Server Agent job is stopped when you log off the console session of the computer. You also notice that the scheduled task or the SQL Server Agent reports a success for the status of the job.
For more information, visit the following Microsoft Developer Network (MSDN) Web sites:

Article ID: 843282 - Last Review: 12/08/2015 07:32:02 - Revision: 3.3

Microsoft SQL Server 2000 Developer Edition, Microsoft SQL Server 2000 Standard Edition, Microsoft SQL Server 2000 Enterprise Edition, Microsoft SQL Server 2000 Personal Edition, Microsoft SQL Server 2000, Workgroup Edition, Microsoft SQL Server 2000 Desktop Engine (Windows), Microsoft SQL Server 2000 Enterprise Edition 64-bit

  • kbnosurvey kbarchive kbkern32dll kbsqlserv2000presp4fix kbfix kbbug kbhotfixserver kbqfe KB843282