<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>A Programmer with Microsoft tools &#187; SqlServer</title>
	<atom:link href="http://msprogrammer.serviciipeweb.ro/category/sqlserver/feed/" rel="self" type="application/rss+xml" />
	<link>http://msprogrammer.serviciipeweb.ro</link>
	<description>A programmer journey through code, books and tools</description>
	<lastBuildDate>Mon, 14 May 2012 06:59:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Monitor SqlServer Stored Proc execution time</title>
		<link>http://msprogrammer.serviciipeweb.ro/2010/06/14/monitor-sqlserver-stored-proc-execution-time/</link>
		<comments>http://msprogrammer.serviciipeweb.ro/2010/06/14/monitor-sqlserver-stored-proc-execution-time/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 04:19:08 +0000</pubDate>
		<dc:creator>Andrei Ignat</dc:creator>
				<category><![CDATA[SqlServer]]></category>
		<category><![CDATA[Homework]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[monitor]]></category>

		<guid isPermaLink="false">http://msprogrammer.serviciipeweb.ro/?p=278</guid>
		<description><![CDATA[I have had the task to made something to monitor what stored procedure, in Sql Server,in most used. The problem that I have had is that the host_name is easily changed by putting, in the connection string WSID (see http://msdn.microsoft.com/en-us/library/ms178598.aspx )
The code is for sql server 2005 and I have not realized without the help [...]]]></description>
			<content:encoded><![CDATA[<p>I have had the task to made something to monitor what stored procedure, in Sql Server,in most used. The problem that I have had is that the host_name is easily changed by putting, in the connection string WSID (see http://msdn.microsoft.com/en-us/library/ms178598.aspx )<br />
The code is for sql server 2005 and I have not realized without the help of http://sqlserver.ro/forums/thread/8332.aspx<br />
So there are the three easy steps to have the monitor proceudre in place:<br />
<strong>1. Define an audit table :</strong></p>
<pre class="brush: sql;">
CREATE TABLE [Audit](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[ProcName] [varchar](128)
	[IdentifierAccess] [varchar](max)
	[DateAccess] [datetime] NULL DEFAULT (getdate())
) ON [PRIMARY]
</pre>
<p><strong>2. Stored proc to insert data :</strong></p>
<pre class="brush: sql;">
alter proc dbo.proc_Log(@procname varchar(100))

as
begin
declare @userid varchar(100)
BEGIN TRY
select @userid=client_net_address from sys.[dm_exec_connections] with(nolock)
where session_id = @@SPID
End TRY
BEGIN CATCH
--GRANT SELECT ON sys.dm_exec_connections TO the user or
--grant view server state to the user ! http://msdn.microsoft.com/en-us/library/ms186717.aspx
set @userid = SUSER_NAME()
End CATCH

INSERT INTO [Audit]
(
[ProcName]
,[IdentifierAccess]
)
VALUES
(@procname,
@userid
)
end
</pre>
<p><strong>3. In each stored procedure put this at beginning</strong></p>
<pre class="brush: sql;">
DECLARE @ProcName nvarchar(128)

    SET @ProcName = OBJECT_NAME(@@PROCID)

    exec proc_Log  @ProcName
</pre>
<p>And this at the end of stored proc :</p>
<pre class="brush: sql;">
    exec proc_Log  @ProcName
</pre>
<p><strong>4. See what the procedure calling are and the time (basic)</strong></p>
<pre class="brush: sql;">
select a1.*,'--',a2.* , datediff(ss,a2.DateAccess,a1.DateAccess)
from [Audit] a1  inner join [Audit] a2 on
a2.ID =
( select max(ID) from [Audit] a2 where a1.ProcName= a2.ProcName and a1.IdentifierAcces=a2.IdentifierAcces and a1.ID &gt; a2.ID )
order by 1
</pre>
<p>From there is a simple way to make a group by to have the sum * count or other relevant data ( which proceudres are most used in what times of the day, and so on)</p>
<p><strong>Work  from home :<br />
1. From the previous select(put it into a  Common table Expression ), see what procedure use most<br />
a) number of uses<br />
b) number of time<br />
2. What is missing from Audit table definition ? (Hint :easy clustered index definition)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://msprogrammer.serviciipeweb.ro/2010/06/14/monitor-sqlserver-stored-proc-execution-time/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sql Server Management Studio free awesome addons</title>
		<link>http://msprogrammer.serviciipeweb.ro/2010/04/05/sql-server-management-studio-free-awesome-addons/</link>
		<comments>http://msprogrammer.serviciipeweb.ro/2010/04/05/sql-server-management-studio-free-awesome-addons/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 04:31:00 +0000</pubDate>
		<dc:creator>Andrei Ignat</dc:creator>
				<category><![CDATA[SqlServer]]></category>
		<category><![CDATA[addons]]></category>

		<guid isPermaLink="false">http://msprogrammer.serviciipeweb.ro/2010/04/05/sql-server-management-studio-free-awesome-addons/</guid>
		<description><![CDATA[The two addons that I can not live without in Sql Server and that, more , are free :

SSMS Tools Pack – now 1.7.5.1 , http://www.ssmstoolspack.com/Download
SQL Search – now1.0 http://www.red-gate.com/products/SQL_Search/

&#160;
The SSMS Tools Pack maintains a history of your commands . More, it saves on the C:\SSMSTools\SQLQueryActionLog
 
&#160;
The Sql Search finds a text in the objects [...]]]></description>
			<content:encoded><![CDATA[<p>The two addons that I can not live without in Sql Server and that, more , are free :
<ol>
<li>SSMS Tools Pack – now 1.7.5.1 , <a title="http://www.ssmstoolspack.com/Download" href="http://www.ssmstoolspack.com/Download">http://www.ssmstoolspack.com/Download</a></li>
<li>SQL Search – now1.0 <a title="http://www.red-gate.com/products/SQL_Search/" href="http://www.red-gate.com/products/SQL_Search/">http://www.red-gate.com/products/SQL_Search/</a></li>
</ol>
<p>&#160;</p>
<p>The SSMS Tools Pack maintains a history of your commands . More, it saves on the C:\SSMSTools\SQLQueryActionLog</p>
<p><a href="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/2010/03/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/2010/03/image_thumb.png" width="925" height="251" /></a> </p>
<p>&#160;</p>
<p>The Sql Search finds a text in the objects in the database – very useful if you decide to change a column name and find all stored procedures that have this reference</p>
<p><a href="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/2010/03/image1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://msprogrammer.serviciipeweb.ro/wp-content/uploads/2010/03/image_thumb1.png" width="977" height="243" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://msprogrammer.serviciipeweb.ro/2010/04/05/sql-server-management-studio-free-awesome-addons/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

