<address id="zp5tt"></address>

    <span id="zp5tt"><dl id="zp5tt"></dl></span>
    <noframes id="zp5tt">

    <address id="zp5tt"></address>

    <noframes id="zp5tt">

          環球網校是美國納斯達克上市企業歡聚時代(NASDAQ:YY)旗下品牌 | 住房和城鄉建設部 建筑人才培訓合作單位
          您現在的位置在: > 計算機類 > 計算機等級考試 > 考試輔導 >

          如何用SQL代理進行SQL探查器跟蹤

          2010-06-27 來源:互聯網 作者:第一考試網

          如何用SQL代理進行SQL探查器跟蹤 #

            SQL 探查器跟蹤使用系統存儲過程來建立。你可以從一個現有的探查器跟蹤中使用SQL命令,并構造你自己的存儲過程來創建和啟動一個SQL探查器跟蹤。你需要使用自己的存儲過程來指定一些額外的設置。這些設置包括運行時間、文件大小和跟蹤輸出文件位置。下面列出了關于如何使用這個存儲過程來創建、執行并且關閉探查器跟蹤的詳細過程。
            創建跟蹤定義
            定義用于構造一個探查器跟蹤的SQL命令最有效的方法是使用SQL探查器。
            1. 啟動SQL探查器并選擇File > New Trace。指定你在跟蹤中想要的事件、字段和過濾器。
            2. 啟動跟蹤然后停止它。
            3. 輸出定義。點擊File > Export > Script Trace Definition > For SQL Server 2005。
            注意,對于SQL Sever 2000 和 2008,請選擇適當的輸出類型。
            4. 保存跟蹤文件。
            創建一個探查器跟蹤存儲過程
            接著,選擇這些輸出跟蹤定義并且用它來創建一個存儲過程。
            1. 使用SSMS來打開上面創建的輸出跟蹤定義。
            2. 在SSMS中打開另一個查詢窗口并粘貼下面的trc_template存儲過程代碼。
            /*
            use Admin
            go #
            */
            CREATE procedure trc_Template @Folder nvarchar(200)
            as
            /*
            Start a 60 minute profiler trace storing the captured output in
            provider folder.
            The folder must exist. A subfolder will be created using the start date
            and time to allow for repeated running of this profile without
            replacing the
            previuos captured trace files.
            On SQL Server 2005, XP_CMDSHELL needs to be enable to create the
            subfolder. You
            might want to disable it when you are done running your scheduled
            trace.
            Sample Command: exec trc_Template @Folder =
            'C:\Output\ProfilerTrace\Template'
            */
            set nocount on
            -- To change the traces duration, modify the following statement
            declare @StopTime datetime ; set @StopTime = dateadd(mi,60,getdate())
            declare @StartDatetime varchar(13) ; set @StartDatetime =
            convert(char(8),getdate(),112) + '_' +

          #


            cast(replace(convert(varchar(5),getdate(),108),':','') as char(4)) --['YYYYMMDD_HHMM']
            declare @rc int
            declare @TraceID int
            declare @TraceFile nvarchar(100)
            declare @MaxFileSize bigint ; set @MaxFileSize = 50 -- The maximum trace file in megabytes
            declare @cmd nvarchar(2000)
            declare @msg nvarchar(200)
            If right(@Folder,1)<>'\' set @Folder = @Folder + '\'
            -- Check if Folder exists
            set @cmd = 'dir ' +@Folder
            exec @rc = master..xp_cmdshell @cmd,no_output
            if (@rc != 0) begin set @msg = 'The specified folder ' + @Folder + '
            does not exist, Please specify an existing drive:\folder '+ cast(@rc as
            varchar(10)) raiserror(@msg,10,1) return(-1)
            end
            --Create new trace file folder
            set @cmd = 'mkdir ' +@Folder+@StartDatetime
            exec @rc = master..xp_cmdshell @cmd,no_output
            if (@rc != 0) begin set @msg = 'Error creating trace folder : ' + #
            cast(@rc as varchar(10)) set @msg = @msg + 'SQL Server 2005 or later
            instance require OLE Automation to been enabled' raiserror(@msg,10,1)
            return(-1)#p#分頁標題#e#
            end
            set @TraceFile = @Folder+@StartDatetime+'\trace'
            exec @rc = sp_trace_create @TraceID output, 2, @TraceFile,
            @MaxFileSize, @StopTime
            if (@rc != 0) begin set @msg = 'Error creating trace : ' + cast(@rc as
            varchar(10)) raiserror(@msg,10,1) return(-1)
            end #

           

          #

            #

          責編:admin 返回頂部  打印

          關于我們聯系我們友情鏈接網站聲明網站地圖廣告服務幫助中心