473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Can Python Parse an MS SQL Trace?

Hi All,

Can Python parse a trace file created with MS SQL's profiler? There
are a few thousand lines in the trace file and I need to find the
insert statements and the stored procedures. Unfortunately, I am not
an SQL guru and was hoping Python could help.

Any pointers are appreciated.

Thanks!

Mike

May 7 '07 #1
4 2897
ky******@gmail.com wrote:
Can Python parse a trace file created with MS SQL's profiler? There
are a few thousand lines in the trace file and I need to find the
insert statements and the stored procedures. Unfortunately, I am not
an SQL guru and was hoping Python could help.
Mike
Mike,

Can I suggest that, since the answer is more to
do with parsing and less to do with MSSQL (which
simply generated the output) that you post an example
of a trace file to some web location to see if anyone
wants to pick up the challenge?

I'm not at work so I don't have access to MSSQL, but
I seem to remember that you can output/save as XML,
which may make things easier (or at least interest a
different group of people in having a look).

I'm quite certain it can by done by Python; I did
consider it myself a couple of months back, but my
colleague spotted the problem before I'd really got
into the code!

TJG
May 7 '07 #2
On May 7, 8:34 am, Tim Golden <m...@timgolden.me.ukwrote:
kyoso...@gmail.com wrote:
Can Python parse a trace file created with MS SQL's profiler? There
are a few thousand lines in the trace file and I need to find the
insert statements and the stored procedures. Unfortunately, I am not
an SQL guru and was hoping Python could help.
Mike

Mike,

Can I suggest that, since the answer is more to
do with parsing and less to do with MSSQL (which
simply generated the output) that you post an example
of a trace file to some web location to see if anyone
wants to pick up the challenge?

I'm not at work so I don't have access to MSSQL, but
I seem to remember that you can output/save as XML,
which may make things easier (or at least interest a
different group of people in having a look).

I'm quite certain it can by done by Python; I did
consider it myself a couple of months back, but my
colleague spotted the problem before I'd really got
into the code!

TJG
Good point. Unfortunately, I think our SQL Server must be too old for
xml (we have version 8). The only save options I see is Trace
Template, Trace File, Trace Table and SQL Script.

Mike

May 7 '07 #3
ky******@gmail.com wrote:
On May 7, 8:34 am, Tim Golden <m...@timgolden.me.ukwrote:
>kyoso...@gmail.com wrote:
>>Can Python parse a trace file created with MS SQL's profiler? There
are a few thousand lines in the trace file and I need to find the
insert statements and the stored procedures. Unfortunately, I am not
an SQL guru and was hoping Python could help.
Mike
Mike,

Can I suggest that, since the answer is more to
do with parsing and less to do with MSSQL (which
simply generated the output) that you post an example
of a trace file to some web location to see if anyone
wants to pick up the challenge?

I'm not at work so I don't have access to MSSQL, but
I seem to remember that you can output/save as XML,
which may make things easier (or at least interest a
different group of people in having a look).

I'm quite certain it can by done by Python; I did
consider it myself a couple of months back, but my
colleague spotted the problem before I'd really got
into the code!

TJG

Good point. Unfortunately, I think our SQL Server must be too old for
xml (we have version 8). The only save options I see is Trace
Template, Trace File, Trace Table and SQL Script.
Yes, you're right; I have clients installed for SQL 2000 &
2005 and it's only under 2005 that I have the XML output
option. The .trc file format is pretty much opaque binary,
and the .sql output only gives you the SQL statements
issued - not the events they're associated with.

One obvious way is to save it to a table and to interrogate
that table. I find that kind of thing a bit cumbersome, but
if XML's not an option, it might be the only way. (FWIW,
I find XML cumbersome too, but that might just be lack
of practice ;)

Running a standard trace and saving to a table, this is
the structure which resulted:

CREATE TABLE [trace_output] (
[RowNumber] [int] IDENTITY (1, 1) NOT NULL ,
[EventClass] [int] NULL ,
[TextData] [ntext] COLLATE SQL_Latin1_General_CP1_CS_AS NULL ,
[NTUserName] [nvarchar] (128) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[ClientProcessID] [int] NULL ,
[ApplicationName] [nvarchar] (128) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[LoginName] [nvarchar] (128) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[SPID] [int] NULL ,
[Duration] [bigint] NULL ,
[StartTime] [datetime] NULL ,
[Reads] [bigint] NULL ,
[Writes] [bigint] NULL ,
[CPU] [int] NULL ,
PRIMARY KEY CLUSTERED
(
[RowNumber]
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
Seems like you might be able to do something with it.
(Possibly just dumping it straight back out to CSV
or XML if that's easier for you than db querying)

TJG
May 8 '07 #4
On May 8, 5:18 am, Tim Golden <m...@timgolden.me.ukwrote:
kyoso...@gmail.com wrote:
On May 7, 8:34 am, Tim Golden <m...@timgolden.me.ukwrote:
kyoso...@gmail.com wrote:
Can Python parse a trace file created with MS SQL's profiler? There
are a few thousand lines in the trace file and I need to find the
insert statements and the stored procedures. Unfortunately, I am not
an SQL guru and was hoping Python could help.
Mike
Mike,
Can I suggest that, since the answer is more to
do with parsing and less to do with MSSQL (which
simply generated the output) that you post an example
of a trace file to some web location to see if anyone
wants to pick up the challenge?
I'm not at work so I don't have access to MSSQL, but
I seem to remember that you can output/save as XML,
which may make things easier (or at least interest a
different group of people in having a look).
I'm quite certain it can by done by Python; I did
consider it myself a couple of months back, but my
colleague spotted the problem before I'd really got
into the code!
TJG
Good point. Unfortunately, I think our SQL Server must be too old for
xml (we have version 8). The only save options I see is Trace
Template, Trace File, Trace Table and SQL Script.

Yes, you're right; I have clients installed for SQL 2000 &
2005 and it's only under 2005 that I have the XML output
option. The .trc file format is pretty much opaque binary,
and the .sql output only gives you the SQL statements
issued - not the events they're associated with.

One obvious way is to save it to a table and to interrogate
that table. I find that kind of thing a bit cumbersome, but
if XML's not an option, it might be the only way. (FWIW,
I find XML cumbersome too, but that might just be lack
of practice ;)

Running a standard trace and saving to a table, this is
the structure which resulted:

CREATE TABLE [trace_output] (
[RowNumber] [int] IDENTITY (1, 1) NOT NULL ,
[EventClass] [int] NULL ,
[TextData] [ntext] COLLATE SQL_Latin1_General_CP1_CS_AS NULL ,
[NTUserName] [nvarchar] (128) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[ClientProcessID] [int] NULL ,
[ApplicationName] [nvarchar] (128) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[LoginName] [nvarchar] (128) COLLATE
SQL_Latin1_General_CP1_CS_AS NULL ,
[SPID] [int] NULL ,
[Duration] [bigint] NULL ,
[StartTime] [datetime] NULL ,
[Reads] [bigint] NULL ,
[Writes] [bigint] NULL ,
[CPU] [int] NULL ,
PRIMARY KEY CLUSTERED
(
[RowNumber]
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

Seems like you might be able to do something with it.
(Possibly just dumping it straight back out to CSV
or XML if that's easier for you than db querying)

TJG
Thanks for the advice. I did the one that had to be done now by hand.
However, I know I'll need to do more of these in the future, so I'll
try it then.

Mike

May 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
0
by: Rafal Zawadzki | last post by:
Hi. I tried earlier to write python zsi mail list, but nobody answered. I am using ZSI 1.7/2.0rc1 with TTPro Soap SDK. The wsdl file can be found here: http://demo.seapine.com/ttsoapcgi.wsdl ...
5
by: Avi Kak | last post by:
Folks, Does regular expression processing in Python allow for executable code to be embedded inside a regular expression? For example, in Perl the following two statements $regex =...
0
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 402 open ( +6) / 3360 closed ( +6) / 3762 total (+12) Bugs : 861 open ( -3) / 6114 closed (+27) / 6975 total (+24) RFE : 228 open...
0
by: Venkat | last post by:
I am very new to Python. I installed Python in Windows and learning it. But i need to install Python on Solaris 8 to automate few things as my build environment is on Solaris. When i tried to...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.