简体   繁体   中英

How to replay a SQL Profiler trace on different database?

I've captured a trace (template: tsql_replay) on our production server for a specific database (filtered by database name). I'd like to replay on it on our test server, but of course the database id is different on the test server.

So far, I've tried loading the trace file into a table and modifying the databaseid with an update query (see below), but Profiler gives me an error when trying to replay it (missing events, etc). If I open the trace file directly, it allows me to replay it. So somehow, either loading into a table or changing the database id messes something up.

What's the correct procedure to capture a trace for replay, and changing the database it should be replayed on?

select * into trace_table
from fn_trace_gettable('f:\trace\trace100222.trc', default)
go
update trace_table
set databaseid = 47
where databaseid = 16

You have to create the trace and save it as Trace XML File for Replay afterwards, the open the XML and Alter the Database ID on the Trace XML.

Beware that if you trace from a sql 2008 to sql 2000, you can't set the end date and hour, because there will be a ODBC DateTime Error.

But other than that it works, normally.

It's two years later, but I was having the exact same problem. Here's how I solved it:

  1. Start SQL Server Profiler
  2. Open the trace file
  3. Replay the trace file to confirm it works
  4. Save the trace file as a table (T1)
  5. Update the table where necessary (in my case, I had to update LoginName to a local user)
  6. Open the updated trace table
  7. Replay the trace

To note, I ran a trace against the process of saving the trace file to a trace table and Profiler does much more than use fn_trace_gettable to write the trace contents to a table. It also seems to add various internal attributes to the trace table through a series of sp_cursor commands that look like this:

exec sp_cursor 180150003,4,0,N'[dbo].[T1]',@EventClass=65528,@BinaryData=0xFFF...

I have had no trouble replaying regular trace files (.trc). They don't have to be XML. This is in SQL 2005. You need to be sure to capture certain events in order to even be able to replay a trace. The TSQL_Replay trace template will help you in this.

When replaying, I tend to turn of the Replay system SPIDs on th Advanced Replay Options tab in the replay dialog. I also tend to save the results to a table for later analysis.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM