<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>My torn data pages</title>
  <link rel="alternate" type="text/html" href="http://resquel.com/ssb/" />
  <link rel="self" href="http://resquel.com/ssb/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2010-08-19T12:26:16.8336216+02:00</updated>
  <author>
    <name>ReSQueL</name>
  </author>
  <subtitle>ReSQueL -- Blog</subtitle>
  <id>http://resquel.com/ssb/</id>
  <generator uri="http://dasblog.info/" version="2.3.9074.18820">DasBlog</generator>
  <entry>
    <title>MS Query not returning text</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2010/08/19/MSQueryNotReturningText.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,c97ef7e3-a574-4286-8eb8-650c2cba696e.aspx</id>
    <published>2010-08-19T12:26:16.8336216+02:00</published>
    <updated>2010-08-19T12:26:16.8336216+02:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am working on an MS Access database that needs to be integrated in a CRM system.
Since the backend of the CRM is SQL Server (why else would I be involved), I migrated
the Access database to SQL Server using the <a title="Download SQL Server Migration Assistant for Access v4.2" href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=5abe098d-c7e1-46c6-994a-09a2856eef0b" rel="nofollow" target="_blank">SQL
Server Migration Assistant for Access v4.2</a> (SSMA for Access). Next I turned my
attention to translating attributes between the systems and unfortunately, a free
text notes field in the Access database is used for a lot of things that need to be
translated to attributes. Some things I know how to translate, but some things have
to be determined by the administrators for the CRM System and Access application.
So I built a query in SQL on the tables formerly stored in the Access database and
used Excel (with MS Query) to create a report for the administrators, so they can
sort out how customer statuses should be translated.
</p>
        <p>
Extremely simplified, the query looked like this; 
</p>
        <blockquote>
          <font size="2">
            <font face="Courier New">
              <font color="#0000ff">SELECT</font> tlbCustomer<font color="#808080">.</font></font>
          </font>
          <font size="2">
            <font face="Courier New">CUST_CODE 
<br /><font color="#808080">  ,</font> tlbCustomer<font color="#808080">.</font></font>
          </font>
          <font size="2">
            <font face="Courier New">PAY_REF 
<br /><font color="#808080">  ,</font><font color="#ff00ff">COALESCE</font><font color="#808080">(</font><font color="#ff00ff">UPPER</font><font color="#808080">(</font><font color="#ff00ff">REPLACE</font><font color="#808080">(</font>tblNotes<font color="#808080">.</font>NOTE_TXT<font color="#808080">,</font><font color="#ff0000">'.'</font><font color="#808080">,</font><font color="#ff0000">''</font><font color="#808080">)),</font><font color="#ff0000">''</font><font color="#808080">)</font><font color="#0000ff">AS</font></font>
          </font>
          <font size="2">
            <font face="Courier New"> NOTE_TXT 
<br /><font color="#0000ff">FROM</font> tlbCustomer <font color="#808080">LEFT</font><font color="#808080">OUTER</font><font color="#808080">JOIN</font></font>
          </font>
          <font size="2">
            <font face="Courier New"> tblNotes 
<br /><font color="#0000ff">      ON</font> tlbCustomer<font color="#808080">.</font>CUST_ID <font color="#808080">=</font> tblNotes<font color="#808080">.</font></font>
          </font>
          <font size="2">
            <font face="Courier New">CUST_ID 
<br /><font color="#0000ff">GROUP</font><font color="#0000ff">BY</font> tlbCustomer<font color="#808080">.</font></font>
          </font>
          <font size="2">
            <font face="Courier New">CUST_CODE 
<br /><font color="#808080">  ,</font> tlbCustomer<font color="#808080">.</font></font>
          </font>
          <font size="2">
            <font face="Courier New">PAY_REF 
<br /><font color="#808080">  ,</font><font color="#ff00ff">UPPER</font><font color="#808080">(</font><font color="#ff00ff">REPLACE</font><font color="#808080">(</font>tblNotes<font color="#808080">.</font>NOTE_TXT<font color="#808080">,</font><font color="#ff0000">'.'</font><font color="#808080">,</font><font color="#ff0000">''</font></font>
          </font>
          <font size="2">
            <font face="Courier New">
              <font color="#808080">)) 
<br /></font>
              <font color="#0000ff">ORDER</font>
              <font color="#0000ff">BY</font>
              <font color="#ff00ff">COUNT</font>
              <font color="#808080">(*)</font>
            </font>
          </font>
          <font color="#0000ff">
            <font size="2" face="Courier New">DESC</font>
            <br />
          </font>
        </blockquote>
        <p>
        </p>
        <p>
The query worked great on SQL, but did not return the text (NOTE_TXT) to Excel. 
</p>
        <p>
To cut the long story short, the original tblNotes.NOTE_TXT field in the Access database
was of type MEMO. SSMA 2008 for Access converted this to nvarchar(max) and somehow
MS Query (in Office 2007) does not return, nor throw an error on, large data types
(varchar(max), nvarchar(max)). A quick test showed that MAX was not really needed;
</p>
        <blockquote>
          <font size="2">
            <font face="Courier New">
              <font color="#0000ff">SELECT</font>
              <font color="#ff00ff">MAX</font>
              <font color="#808080">(</font>
              <font color="#ff00ff">LEN</font>
              <font color="#808080">(</font>tblNotes<font color="#808080">.</font>NOTE_TXT<font color="#808080">))</font><font color="#0000ff">FROM</font> tblNotes</font>
          </font>
          <font size="+0">
            <br />
          </font>
        </blockquote>
        <p>
So modify the query to return NOTE_TXT as nvarchar(256) does the trick;
</p>
        <blockquote>
          <font size="2">
            <font face="Courier New">
              <font color="#0000ff">SELECT</font> tlbCustomer<font color="#808080">.</font></font>
          </font>
          <font size="2">
            <font face="Courier New">CUST_CODE 
<br /><font color="#808080">  ,</font> tlbCustomer<font color="#808080">.</font></font>
          </font>
          <font size="2">
            <font face="Courier New">PAY_REF 
<br /><font color="#808080">  ,</font><font color="#ff00ff">CAST</font></font>
          </font>
          <font size="2">
            <font face="Courier New">
              <font color="#808080">( 
<br /></font>
              <font color="#ff00ff">      COALESCE</font>
              <font color="#808080">(</font>
              <font color="#ff00ff">UPPER</font>
              <font color="#808080">(</font>
              <font color="#ff00ff">REPLACE</font>
              <font color="#808080">(</font>tblNotes<font color="#808080">.</font>NOTE_TXT<font color="#808080">,</font><font color="#ff0000">'.'</font><font color="#808080">,</font><font color="#ff0000">''</font><font color="#808080">)),</font><font color="#ff0000">''</font><font color="#808080">)</font></font>
          </font>
          <font size="2">
            <font face="Courier New">
              <br />
              <font color="#0000ff">    AS</font>
              <font color="#0000ff">nvarchar</font>
              <font color="#808080">(</font>256<font color="#808080">))</font><font color="#0000ff">AS</font></font>
          </font>
          <font size="2">
            <font face="Courier New"> NOTE_TXT 
<br /><font color="#0000ff">FROM</font> tlbCustomer <font color="#808080">LEFT</font><font color="#808080">OUTER</font><font color="#808080">JOIN</font></font>
          </font>
          <font size="2">
            <font face="Courier New"> tblNotes 
<br /><font color="#0000ff">      ON</font> tlbCustomer<font color="#808080">.</font>CUST_ID <font color="#808080">=</font> tblNotes<font color="#808080">.</font></font>
          </font>
          <font size="2">
            <font face="Courier New">CUST_ID 
<br /><font color="#0000ff">GROUP</font><font color="#0000ff">BY</font> tlbCustomer<font color="#808080">.</font></font>
          </font>
          <font size="2">
            <font face="Courier New">CUST_CODE 
<br /><font color="#808080">  ,</font> tlbCustomer<font color="#808080">.</font></font>
          </font>
          <font size="2">
            <font face="Courier New">PAY_REF 
<br /><font color="#808080">  ,</font><font color="#ff00ff">UPPER</font><font color="#808080">(</font><font color="#ff00ff">REPLACE</font><font color="#808080">(</font>tblNotes<font color="#808080">.</font>NOTE_TXT<font color="#808080">,</font><font color="#ff0000">'.'</font><font color="#808080">,</font><font color="#ff0000">''</font></font>
          </font>
          <font size="2">
            <font face="Courier New">
              <font color="#808080">)) 
<br /></font>
              <font color="#0000ff">ORDER</font>
              <font color="#0000ff">BY</font>
              <font color="#ff00ff">COUNT</font>
              <font color="#808080">(*)</font>
            </font>
          </font>
          <font color="#0000ff">
            <font size="2" face="Courier New">DESC</font>
            <br />
          </font>
        </blockquote>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=c97ef7e3-a574-4286-8eb8-650c2cba696e" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Service Broker can make your transaction log big</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2010/07/24/ServiceBrokerCanMakeYourTransactionLogBig.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,af4f0b36-0b2f-47f7-bbe6-61216f6f9be3.aspx</id>
    <published>2010-07-24T18:48:00.614+02:00</published>
    <updated>2010-07-24T18:48:00.614+02:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Sometimes one is confronted with forgetting an option... It all started with a database
that had a single data file of 1.8 GB and a transaction log more than 6 times the
size of that. Usually that would be a database in full recovery model and no transaction
log backups. This database was in simple recovery model though and according to the
Disk Usage report, 99.99% of the transaction log was free. So a DBCC SHRINKFILE should
solve the problem, however DBCC SHRINKFILE solved nothing, the log remained at about
11 GB.
</p>
        <p>
A query on sys.databases learned that this particular database had ACTIVE_TRANSACTION
for log_reuse_wait_desc. A peek in Activity Monitor then showed that there was an
open transaction for the database; a DELETE task with a huge wait time and the BROKER_RECEIVE_WAITFOR
wait type.
</p>
        <p>
Then it occurred to me this is the database that used to have <a title="Deadlock Alerts Through Event Notification" href="http://resquel.com/ssb/2009/03/02/DeadlockAlertsThroughEventNotification.aspx" target="_blank">a
deadlock problem</a>. After implementing some procedure fixes, there haven’t been
any deadlocks for over a half year and neither has the server (or service) been shutdown
in between.
</p>
        <p>
The stored procedure on the queue does a receive, but no timeout associated to it.
Effectively this means that the receive will wait inside the transaction, until a
messages comes into the queue. That hasn’t happened in the last six months. The resolution
is simple, add the TIMEOUT option to the RECEIVE and the procedure will stop when
there wasn’t any work to be done for the specified amount of time (in milliseconds).
For the code, see the post “<a title="Deadlock Alerts Through Event Notification" href="http://resquel.com/ssb/2009/03/02/DeadlockAlertsThroughEventNotification.aspx" target="_blank">Deadlock
Alerts Through Event Notification</a>”, which has been updated with the TIMEOUT option.
</p>
        <p>
After altering the procedure, kill the spid. Service Broker will restart, but now
with the TIMEOUT option in the procedure and stop after the specified amount of time
has elapsed without messages arriving in the queue.
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=af4f0b36-0b2f-47f7-bbe6-61216f6f9be3" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Restoring Databases with big transaction logs (wishful thinking)</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2010/02/26/RestoringDatabasesWithBigTransactionLogsWishfulThinking.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,05ac51dd-6982-4e80-86b6-0d9c4ecb5f1f.aspx</id>
    <published>2010-02-26T21:26:02.09+01:00</published>
    <updated>2010-02-26T21:26:02.09+01:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
When restoring a backup of a database, SQL Server recreates the files with the same
sizes as listed in the backup, or at least tries to do so. The only option you have,
is specifying the path for each file. Generally not a problem, but every now and then
I encounter a database with a transaction log about 10 to 50 times the size of the
data file(s) . . . yep, full recovery model and just daily full backups. I am the
first to acknowledge transaction logs backups are key to prevent this situation, but
the next best thing still is that recent valid database backup. . . and then you can’t
restore it, because the 200 GB to write that big empty file called transaction log
cannot be allocated.
</p>
        <p>
Today was one of those days; 
</p>
        <blockquote>
          <font color="#ff0000" face="Courier">Msg 3257, Level 16, State 1, Line
1 
<br />
There is insufficient free space on disk volume 'D:\' to create the database. The
database requires 101197938688 additional free bytes, while only 19386400768 bytes
are available. 
<br />
Msg 3119, Level 16, State 4, Line 1 
<br />
Problems were identified while planning for the RESTORE statement. Previous messages
provide details. 
<br />
Msg 3013, Level 16, State 1, Line 1 
<br />
RESTORE DATABASE is terminating abnormally. 
<br /></font>
        </blockquote>
        <p>
Surely I wouldn’t be the only one having problems with this and I found two others
on connect;
</p>
        <ul>
          <li>
            <a href="https://connect.microsoft.com/SQLServer/feedback/details/532739" target="_blank">Option
to resize datafile/transaction log during a backup or restore operation</a>
          </li>
          <li>
            <a href="https://connect.microsoft.com/SQLServer/feedback/details/125287/" target="_blank">Restore
option to restore minimum file sizes</a>
          </li>
        </ul>
        <p>
I voted (as important) for both items, though the second one is already closed. Yet
I was triggered by the comments from the MS-people to ask for a specific solution
towards the transaction log;
</p>
        <h3>
          <a href="https://connect.microsoft.com/SQLServer/feedback/details/536710" target="_blank">RESTORE
DATABASE ... WITH STUB_LOG</a>
        </h3>
        <p>
One of the habits of RESTORE DATABASE is that it wants to allocate the log size (and
files) as found in the backup. Strange, as the size of those files is the result of
past activity (not contained in the backup being restored). The only space needed
in the transaction log, is that of the activity during the backup. Additional space
requirements may exist for subsequent restores of differential backups and log backups
(in norecovery or standby) or future activity (after recovery), but that isn’t an
issue as the log files would grow again during these restores. 
<br /><br />
The only real issue I can think of is having a database with fixed size transaction
log file(s), which means no auto grow. So for a WITH STUB_LOG option to work properly
in these scenarios, it may need to imply that the log file(s) are always set to unrestricted
auto grow (possibly only honoring the original increment). 
<br /><br />
It would at least prevent me from having to allocate 100GB for an empty transaction
log on 20GB available. 
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=05ac51dd-6982-4e80-86b6-0d9c4ecb5f1f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Free SQL Server learning events (March 2010)</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2010/02/09/FreeSQLServerLearningEventsMarch2010.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,feae038f-b53c-4b46-833c-049ec01b5b66.aspx</id>
    <published>2010-02-09T10:43:22.3304542+01:00</published>
    <updated>2010-02-09T10:43:56.1214542+01:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <category term="Train_Cert" label="Train_Cert" scheme="http://resquel.com/ssb/CategoryView,category,TrainCert.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you're interested in expanding your skills in SQL Server, check out these events;
</p>
        <ul>
          <li>
            <a title="Quest Virtual Training for SQL Server" href="http://www.vconferenceonline.com/shows/spring10/quest/" target="_blank">Quest
Virtual Training for SQL Server</a>, an online and worldwide available event on Wednesday
March 3<sup>rd</sup></li>
          <li>
            <a title="SQL Zaterdag" href="http://www.sqlzaterdag.nl" target="_blank">SQL Zaterdag</a>,
hosted at InfoSupport in Veenendaal, Netherlands at Saturday March 6<sup>th</sup></li>
        </ul>
        <p>
Happy learning.
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=feae038f-b53c-4b46-833c-049ec01b5b66" />
      </div>
    </content>
  </entry>
  <entry>
    <title>MCP added value</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/12/18/MCPAddedValue.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,96d24ef8-78f7-44c5-98df-823a466f3ba0.aspx</id>
    <published>2009-12-18T11:47:33.109+01:00</published>
    <updated>2009-12-18T11:47:33.109+01:00</updated>
    <category term="Train_Cert" label="Train_Cert" scheme="http://resquel.com/ssb/CategoryView,category,TrainCert.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Microsoft recently launched a Virtual Business Card site for Microsoft Certified Professionals.
So if you ever passed one or more of those Microsoft exams in the NT 4.0 or later
eras, check out the <a href="http://www.mcpvirtualbusinesscard.com">www.mcpvirtualbusinesscard.com</a> site
(Windows Live ID sign in to connect to you records in Microsoft's certification database).
</p>
        <p>
I set my profile page up to show off the credentials..
</p>
        <iframe frameborder="0" scrolling="no" width="397px" height="180px" src="https://www.mcpvirtualbusinesscard.com/VBCServer/StanSegers/card">
        </iframe>
        <p>
Also had a look at including the transcript, but that would be a 13-page pdf, a bit
of overkill if you ask me.
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=96d24ef8-78f7-44c5-98df-823a466f3ba0" />
      </div>
    </content>
  </entry>
  <entry>
    <title>SQL Server day 2009</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/12/04/SQLServerDay2009.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,98faceda-3d98-4059-9e5c-defe82adde2b.aspx</id>
    <published>2009-12-04T14:35:00.216+01:00</published>
    <updated>2009-12-04T14:35:00.216+01:00</updated>
    <category term="Intergation Services" label="Intergation Services" scheme="http://resquel.com/ssb/CategoryView,category,IntergationServices.aspx" />
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <category term="Train_Cert" label="Train_Cert" scheme="http://resquel.com/ssb/CategoryView,category,TrainCert.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Yesterday I visited the <a href="http://sqlserverday.be" target="_blank">SQL Server
day 2009</a>, organized by the Belgian SQL Server User Group <a href="http://sqlug.be/" target="_blank">SQLUG.BE</a>,
in Mechelen. Congratulations on the event guys!
</p>
        <p>
After the keynote by Microsoft Belgium (I wish they had talked a little bit more about
SQL Azure), I visited the session by Henk van der Valk on world record ETL... now
Henk has control over some top notch iron, but that doesn't mean his tips don't apply
to a modest setup. Henk also mentioned he recently joined the blogsphere at <a href="http://www.henkvandervalk.com">www.henkvandervalk.com</a>.
</p>
        <p>
Next I sat (sorry I have to say so) horrible sponsored session by <a href="http://www.quest.com" target="_blank">Quest</a>...
and this has nothing to do with the FogLight product. On another occasion (an afternoon
session by Quest Netherlands) I witnessed the possibilities of Foglight (for .NET,
SQL Server and VMware) and I must say it's a good looking product. However we got
30 minutes of boring listing of challenges and day to day problems (as if we weren't
aware of them already) and in the end got some screenshots, which were completely
out of context. I would have be completely lost in the presentation if I hadn't been
to the session earlier by Quest NL.
</p>
        <p>
After that, I meant to sit the session "Reporting Services a DBA's tool? YES!!!",
but since the agenda card was a little confusing (or better said, I didn't pay enough
attention) I walked into the session by <a href="http://www.u2u.be/res/nico.aspx" target="_blank">Nico
Jacobs</a> on "Handling XML in SQL Server". Funny, as there was nothing new for me
in the session but still I really enjoyed it... most important because as a trainer
you rarely get an opportunity to see one of your colleagues at work on a familiar
subject. Thanks Nico, I really enjoyed it.
</p>
        <p>
The other session I attended was on "Policy Based Management", again by Nico Jacobs.
I hoped it would go deeper into the possibilities of implementing it for SQL Server
2005 and SQL Server 2000. Unfortunately that was not the case, so I'll have to dive
into the <a href="http://epmframework.codeplex.com/" target="_blank">Enterprise Policy
Management Framework</a> and PowerShell without a quick start. But again, it was a
joy listening to Nico.
</p>
        <p>
Final session and closing keynote was by <a href="http://cwebbbi.spaces.live.com/" target="_blank">Chris
Webb</a> on PowerPivot (a.k.a. Gemini). It wasn't my first glance at Gemini, but it
definitely is the kind of quick start I was looking for. Sitting a session like that
saves a day of looking for stuff.
</p>
        <p>
All-in-all, a day well spent.
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=98faceda-3d98-4059-9e5c-defe82adde2b" />
      </div>
    </content>
  </entry>
  <entry>
    <title>SQL Server linked servers with Windows Authentication</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/11/21/SQLServerLinkedServersWithWindowsAuthentication.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,fafaec29-44bb-4ca2-bf2d-ddfba92f6352.aspx</id>
    <published>2009-11-21T20:56:50.995+01:00</published>
    <updated>2009-11-21T20:56:50.995+01:00</updated>
    <category term="Linked Server" label="Linked Server" scheme="http://resquel.com/ssb/CategoryView,category,LinkedServer.aspx" />
    <category term="Security" label="Security" scheme="http://resquel.com/ssb/CategoryView,category,Security.aspx" />
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Creating linked servers between two instances of SQL Server may not always be as straight
forward as hoped. To make it more complicated, interference may be caused by matters
beyond the control of the database administrator; Active Directory. After creating
a linked server, being able to successfully use it may be the real challenge, it may
even work for one user and fail for another.
</p>
        <h3>Service Account
</h3>
        <p>
To communicate successfully in a domain environment, the service account for your
database engine is the first to check/configure. Possible choices for the service
account are;
</p>
        <ul>
          <li>
Domain User (recommended) 
</li>
          <li>
Local User 
</li>
          <li>
LocalSystem 
</li>
          <li>
LocalService 
</li>
          <li>
NetworkService (recommended)</li>
        </ul>
        <p>
From those options, a local user or LocalService for the service account will eventually
stop you. In both cases a SQL Server has the permission set of user on the machine
where SQL Server operates, with no identity on the network. In case the SQL Server
has to connect to any remote resource, it will do so as an anonymous user (null session).
Unless you want to be absolutely sure that SQL Server should never do anything beyond
anonymous on the network, you can go this route... but hey, you're reading about linked
servers, so just drop the thought of using a local user or LocalService.
</p>
        <p>
Valid options to enable SQL Server to operate on the network are LocalSystem, NetworkService
and Domain User. All have the potential to work well, but LocalSystem is not recommended
from a security perspective. LocalSystem has the permission set of an administrator
on the system where SQL Server operates, anyone obtaining control over your SQL Server
has full access to the underlying operating system (think about the damage that could
be done when xp_cmdshell is enabled). From a network perspective, LocalSystem and
NetworkService are identical; when the SQL Server operates over the network, it will
do so under the credentials of the Windows machine. With a domain user as service
account, SQL Server has user permissions locally (as is the case with NetworkService,
LocalService and a local user), on the network SQL Server will present the credentials
of the domain user.
</p>
        <p>
So two good options remain; NetworkService and a domain user. Which one you chose
mainly depends on the advantages of one over the other;
</p>
        <ul>
          <li>
NetworkService: 
<ul><li>
No account or password management in Active Directory 
</li><li>
Service Principal Names are automatically generated</li></ul></li>
          <li>
Domain User 
<ul><li>
Multiple instances on different machines can have the same identity which is required
for clustering. 
</li><li>
Transparent security for Database Mirroring.  
</li><li>
Usually SQL Agent will be the same account, this makes things easier with Log Shipping
and Replication. <a href="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/ChangeServiceAccount_2.png"><img style="border-right-width: 0px; margin: 5px 0px 5px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="ChangeServiceAccount" align="right" src="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/ChangeServiceAccount_thumb.png" width="244" height="130" /></a></li><li>
Improved access to Service Master Key (in case you don't have a backup of the key
itself). <a title="BOL -- ALTER SERVICE MASTER KEY" href="http://technet.microsoft.com/en-us/library/ms187788(SQL.100).aspx" target="_blank">--&gt;</a></li></ul></li>
        </ul>
        <p>
Personally, I favor using a domain user.
</p>
        <p>
Should you find that you need to change the Service Account; use the "SQL Server Configuration
Manager" 
</p>
        <h3>Configuring and using a SQL Server linked server for Windows Authentication
</h3>
        <p>
          <a href="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/NewLinkedServer1_2.png">
            <img style="border-right-width: 0px; margin: 5px 5px 5px 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="NewLinkedServer1" align="left" src="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/NewLinkedServer1_thumb.png" width="215" height="143" />
          </a>There
are two ways to go about the configuration; graphically and via stored procedure.
The graphical approach brings up a dialog, where just a little configuration is needed.
</p>
        <p>
On the General page, select the server type to be SQL Server (choosing SQL Server
Native or OLEDB drivers will work too, but require extra configuration) and type the
name of the target instance using the flat name or FQDN followed by a backslash and
instance name in case of a named instance.
</p>
        <p>
On the Security page, select the option to "Be made using the login's current security
context", which effectively tells SQL Server to impersonate or delegate the login
requesting access though the linked server.
</p>
        <p>
On the Server Options page, verify that Data Access is set to True. To see the stored
procedures involved, either use the Script button on top of the dialog instead of
pressing ok or right-click a configured linked server and "Script Linked Server as
&gt;".
</p>
        <p>
To avoid running into (later explained) problems when creating linked servers, create
the linked server from a shell (interactive or remote desktop) on the Windows machine
where the linked server is configured.
</p>
        <p>
To use the linked server, issue the query 
</p>
        <blockquote>
          <p>
SELECT TOP 50 * FROM [HOST.NET.LOCAL\INSTANCE].AdventureWorks.Sales.SalesOrderDetail 
</p>
        </blockquote>
        <p>
Note that the linked server HOST.NET.LOCAL\INSTANCE is enclosed in braces, which is
required when the server name is fully qualified and/or when it is a named instance.
If you don't want to expose host and/or instance names, consider creating an alias
in "SQL Server Configuration Manager" under client configuration and point the linked
server to the alias.
</p>
        <h3>Impersonation and delegation
</h3>
        <p>
During the configuration (Security page) impersonation and delegation were mentioned.
Also to avoid problems while configuring a linked server, the best way to do so was
on the server where the linked server was to be created. The reason to do so is to
avoid delegation. Below are a summary of impersonation and delegation (and links to
a more complete overview). Windows accounts will be impersonated if necessary, Windows
accounts will not be delegated unless both account and delegating system are configured
to do so. 
</p>
        <p>
Impersonation happens when a process connects to resources pretending to have the
identity of it's caller. Like when a user Bobbie is connected to SQLINST1 and issues
a query for a table via a linked server on SQLINST2. Depending on the configuration
of the linked server, SQLINST1 will pretend to be Bobbie when connecting on Bobbies
behalf to SQLINST2. For a more detailed overview of impersonation, check the <a title="What is impersonation" href="http://alt.pluralsight.com/wiki/default.aspx/Keith.GuideBook/WhatIsImpersonation.html" target="_blank">Pluralsight-wiki
on impersonation</a>. Note that impersonation is limited to the  system where
process making the call is active.
</p>
        <p>
Delegation is much like impersonation, with the additional feature that delegation
is not limited to the system of the process making the call. Because the process now
has to forward the credentials to another system and prove to operate on behalf of
someone else than the system itself, the <a title="What is Kerberos" href="http://alt.pluralsight.com/wiki/default.aspx/Keith.GuideBook/WhatIsKerberos.html" target="_blank">Kerberos</a> protocol
is required (that or knowledge of the password of the delegated user). For a more
detailed overview of delegation, check the <a title="What is delegation" href="http://alt.pluralsight.com/wiki/default.aspx/Keith.GuideBook/WhatIsDelegation.html" target="_blank">Pluralsight-wiki
on delegation</a>.
</p>
        <p>
          <a href="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/UserDelegationProperty_2.png">
            <img style="border-right-width: 0px; margin: 5px 0px 5px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="UserDelegationProperty" align="right" src="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/UserDelegationProperty_thumb.png" width="204" height="244" />
          </a>From
the perspective of Windows systems, Bobbie (DOMAIN\Bobbie) is logged in on a typical
client system (Windows XP, Vista or 7) and uses an application that connects to SERVER1\SQLINST1.
In SQLINST1 two linked servers are configured; SERVER1 (being the default instance
on SERVER1) and SERVER2\SQLINST1. The context of the application is DOMAIN\Bobbie
and thus an access token for DOMAIN\Bobbie is handed to SERVER1 (for logging in on
the SQL Server service SERVER1\SQLINST1). When the application issues a query for
an object on the default instance of SERVER1, one local process on SERVER1 has to
impersonate DOMAIN\Bobbie to the other local process on SERVER1. This will succeed
and can work both with NTLM and Kerberos, because SERVER1 trusts itself and the domain;
DOMAIN\Bobbie was authenticated by the domain and is only used by SERVER1 locally. 
</p>
        <p>
Next the application calls for SERVER2 and now the challenge is on! Bobbie get's a 
</p>
        <blockquote>
          <p>
Msg 18456, Level 14, State 1, Line 1<br />
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
</p>
        </blockquote>
        <p>
          <a href="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/SystemDelegationProperty_2.png">
            <img style="border-right-width: 0px; margin: 5px 5px 5px 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="SystemDelegationProperty" align="left" src="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/SystemDelegationProperty_thumb.png" width="220" height="244" />
          </a>SERVER2
does not trust SERVER1 and therefor will not accept the claim of SERVER1 that it acts
on Bobbies behalf, SERVER2 wants to see PROOF! One way of proof would be if SERVER1
had the password of Bobbie, indicating that Bobbie fully trusts SERVER1... but Lesson
number 1; never give anyone your password. Lesson number 2; don't write it on a Post-It...
Lesson number 3; don't trust computers that violate lessons 1 or 2. The other option
is to turn to a mutually trusted third party: the domain, but now the configuration
needs to be right for Kerberos.
</p>
        <p>
For Kerberos to do it's trick, the user (Domain\Bobbie) and the machine delegating
(SERVER1) the user have to be trusted for delegation. This is sufficient if the SQL
Server services on SERVER1\SQLINST1 and SERVER2 run as NetworkService.
</p>
        <p>
In case SERVER1\SQLINST1 is running under a domain user account, trust that user account
for delegation, not the server.
</p>
        <h3>Service Principal Name
</h3>
        <p>
Kerberos distinguishes three roles; 
</p>
        <ul>
          <li>
Key Distribution Center (KDC), in Active Directory this role is held by the Domain
Controllers. 
</li>
          <li>
Client, these are the users. 
</li>
          <li>
Server, these are the computers in your network.</li>
        </ul>
        <p>
With this basic division of roles, things work well in a domain, until a service account
like that of the SQL Server database engine is a domain user. If so, that particular
domain user should be made a server too. To mark an account as a service, a Service
Principal Name must be registered. With NetworkService, this was done by the server
(because servers can write SPN's on their own behalf), for any other account, by default
only Domain Administrators can write an SPN. Use the SetSPN tool to mark an account
as Service Principal Name, SetSPN can be <a title="SetSPN" href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=5fd831fd-ab77-46a3-9cfe-ff01d29e5c46" target="_blank">downloaded</a>,
is part of the Windows Server 2003 Support Tools and is installed on Windows Server
2008 with the AD DS role.
</p>
        <p>
To register an SPN for a service account, use the following syntax:
</p>
        <blockquote>
          <p>
SetSPN -a MsSqlSvc/<font color="#0000ff">server1.domain.local</font>:<font color="#0000ff">1433
domain\user</font></p>
          <p>
SetSPN -a MsSqlSvc/<font color="#0000ff">server1</font>:<font color="#0000ff">1433
domain\user</font></p>
        </blockquote>
        <p>
Substitute the blue parts in the syntax for the server names (FQDN and NetBIOS), the
port where SQL Server listens (this could be different from 1433, especially when
registering an SPN for additional instances) and the domain user account used as SQL
Server service account.
</p>
        <p>
When running more SQL Server instances under the same domain account, it may be useful
to check the approach listed in Step 3 of <a title="How to use Kerberos authentication in SQL Server" href="http://support.microsoft.com/kb/319723" target="_blank">How
to use Kerberos authentication in SQL Server</a>, so the AD-people have to be called
upon only once for the service account, not for every instance installation.
</p>
        <p>
Reference Environment
</p>
        <p>
          <a href="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/ReferenceEnvironment_4.png">
            <img style="border-right-width: 0px; margin: 5px 0px 5px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="ReferenceEnvironment" align="right" src="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/ReferenceEnvironment_thumb_1.png" width="244" height="215" />
          </a> As
reference environment (may be a layout for a test-network), the following machines,
users and services are used in a single domain configuration;
</p>
        <ul>
          <li>
Windows Server 2003 or 2008: DC1 (domain controller), SERVER1 (member), SERVER2 (member) 
</li>
          <li>
Windows XP, Vista or 7: CLIENT (member) 
</li>
          <li>
SQL Server 2005 or 2008: SERVER1 (default instance) tcp 1433 static, SERVER1\SQLINST1
tcp dynamic (named instance), SERVER2\SQLINST1 (named instance) tcp 1433 static</li>
        </ul>
        <p>
To make it work, user Domain\Bobbie has to be trusted for delegation in all four scenario's.
Depending on the service accounts for SERVER1\SQLINST1 and SERVER2\SQLINST2, use the
following settings
</p>
        <table border="1" cellspacing="0" cellpadding="2" width="100%">
          <tbody>
            <tr>
              <td valign="top">
                <strong>Service account for SERVER1\SQLINST1</strong>
              </td>
              <td valign="top">
                <strong>Service account for SERVER2\SQLINST1</strong>
              </td>
              <td valign="top">
                <strong>Users and or computers to be trusted for delegation</strong>
              </td>
              <td valign="top">
                <strong>SPN's to create</strong>
              </td>
            </tr>
            <tr>
              <td valign="top">
NetworkService</td>
              <td valign="top">
NetworkService</td>
              <td valign="top">
SERVER1<br />
DOMAIN\Bobbie</td>
              <td valign="top">
&lt;none&gt;</td>
            </tr>
            <tr>
              <td valign="top">
NetworkService</td>
              <td valign="top">
DOMAIN\SRV_SQL2</td>
              <td valign="top">
SERVER1<br />
DOMAIN\Bobbie</td>
              <td valign="top">
MSSQLSvc/server2.domain.local:1433 DOMAIN\SRV_SQL2</td>
            </tr>
            <tr>
              <td valign="top">
DOMAIN\SRV_SQL1</td>
              <td valign="top">
NetworkService</td>
              <td valign="top">
DOMAIN\SRV_SQL1<br />
DOMAIN\Bobbie</td>
              <td valign="top">
&lt;none&gt;</td>
            </tr>
            <tr>
              <td valign="top">
DOMAIN\SRV_SQL1</td>
              <td valign="top">
DOMAIN\SRV_SQL2</td>
              <td valign="top">
DOMAIN\SRV_SQL1<br />
DOMAIN\Bobbie</td>
              <td valign="top">
MSSQLSvc/server2.domain.local:1433 DOMAIN\SRV_SQL2</td>
            </tr>
          </tbody>
        </table>
        <h3>Things to consider
</h3>
        <p>
          <a href="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/AdjustKerberosIntervals_2.png">
            <img style="border-right-width: 0px; margin: 5px 5px 5px 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="AdjustKerberosIntervals" align="left" src="http://resquel.com/ssb/content/binary/WindowsLiveWriter/ImpersonationanddelegationwithSQLServer_14C28/AdjustKerberosIntervals_thumb.png" width="244" height="104" />
          </a> When
working with Kerberos, tickets are granted for a longer period of time (typically
10 hours), so configuration changes usually take a longer time to apply. Use the KERBTRAY
and/or KLIST <a title="Windows Server 2003 Resource Kit" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&amp;displaylang=en" target="_blank">resource
kit utilities</a> to view and purge tickets, in order to speed things up (avoids rebooting
systems or logging off/on users). Alternatively, consider shortening the ticket lifetimes
to the minimum; 10 minutes for services and 1 hour for users.
</p>
        <p>
When configuring the linked servers, it was best to do so at the server where the
linked server is configured from. Depending on your role you may be a domain admin,
so should domain admins be delegated in order to make setting up linked servers easier?
Rather not! Imagine someone installed malicious program or script on a system that
is trusted for delegation and somehow a domain administrator executes this program
or script. It could hurt any system or user in your network.
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=fafaec29-44bb-4ca2-bf2d-ddfba92f6352" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Bram</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/08/05/Bram.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,2ad0edcd-3c42-4915-bb29-2216e440b95f.aspx</id>
    <published>2009-08-05T14:39:29.984+02:00</published>
    <updated>2009-08-05T14:42:18.157+02:00</updated>
    <category term="ReSQueL" label="ReSQueL" scheme="http://resquel.com/ssb/CategoryView,category,ReSQueL.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://resquel.com/ssb/content/binary/WindowsLiveWriter/Bram_CE1F/Bram_Stan.jpg">
            <img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 10px; border-top: 0px; border-right: 0px" border="0" alt="Bram_Stan" align="right" src="http://resquel.com/ssb/content/binary/WindowsLiveWriter/Bram_CE1F/Bram_Stan_thumb.jpg" width="180" height="260" />
          </a>I
knew this was coming and still I was taken by surprise; my son Bram was born last
week (July 27th). An event like that turns your life upside down, forever. I'm not
in the habit of putting personal stuff on the net, but this is worth the exception.
So here they are, a proud father and his one day old son. 
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=2ad0edcd-3c42-4915-bb29-2216e440b95f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>NULL in unique index (where SQL Server gets it wrong)</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/07/22/NULLInUniqueIndexWhereSQLServerGetsItWrong.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,19cb3089-1ca4-4c50-b85b-2375d8de1f1c.aspx</id>
    <published>2009-07-22T15:00:57.137+02:00</published>
    <updated>2009-07-22T15:01:19.93+02:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Sometimes SQL Server gets it wrong, UNIQUE constraints and NULL is one of the parts
where it is wrong. People call it a bug and request for it to be fixed, Microsoft
calls requests to fix it common and offers workarounds and overall current SQL Server
behavior does not adhere to the standard (ISO-9075).
</p>
        <p>
To see the bug reports (and vote); <a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=126533" target="_blank">126533</a>, <a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=299229" target="_blank">299229</a>, <a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=311223" target="_blank">311223</a> (closed), <a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=387273" target="_blank">387273</a>.
Basically they are each others duplicates and from those, the request 299229 has most
attention and the best discussion.
</p>
        <p>
Available workarounds;
</p>
        <ul>
          <li>
Filtered index (starting with SQL Server 2008) 
</li>
          <li>
Indexed view (starting with SQL Server 2000) 
</li>
          <li>
Triggers (not recommended as the check is after the modification is completed and
if invalid has to perform a rollback)</li>
        </ul>
        <p>
... and don't say Microsoft didn't get it right because it's Microsoft... Access implements
UNIQUE constraints correctly.
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=19cb3089-1ca4-4c50-b85b-2375d8de1f1c" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Migration</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/06/17/Migration.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,9f424662-7e1f-4f60-a7d5-ed2755ea6499.aspx</id>
    <published>2009-06-17T21:31:05.3181969+02:00</published>
    <updated>2009-06-17T21:31:05.3181969+02:00</updated>
    <category term="dasBlog" label="dasBlog" scheme="http://resquel.com/ssb/CategoryView,category,dasBlog.aspx" />
    <category term="Hardware" label="Hardware" scheme="http://resquel.com/ssb/CategoryView,category,Hardware.aspx" />
    <category term="ReSQueL" label="ReSQueL" scheme="http://resquel.com/ssb/CategoryView,category,ReSQueL.aspx" />
    <category term="SBS" label="SBS" scheme="http://resquel.com/ssb/CategoryView,category,SBS.aspx" />
    <category term="Windows Server 2008" label="Windows Server 2008" scheme="http://resquel.com/ssb/CategoryView,category,WindowsServer2008.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been holding this one off for quite some time, but finally bit the bullet...
migrate the server.Coming from Windows Small Business Server 2003 (32-bit) going to
Windows Server 2008 with Exchange 2007 (both x64), including transferring the web
site. There were a few nasty pieces in the process and I didn't have/take the time/resources
to test it all though before jumping in... so I got a disruption of about one hour
for the blog and inbound smtp.
</p>
        <p>
First issue I encountered was the installation of the server, which I ordered from
Dell without operating system. I am a <a href="https://partner.microsoft.com/40013779" target="_blank">Microsoft
Action Pack</a> subscriber, so I slammed the 64-bit Windows Server from the Action
Pack on the system, entered the Product Key and then went on to phone based activation.
After putting in the last confirmation code and pushing the next button... my activation
wasn't accepted!!! ... to cut a long story short, after dozens of voice menu selections
and 4 persons, I found the guy who could help me out: Philip. Though it still toke
Philip and me about 20 minutes to find the actual problem... I wasn't an Action Pack
subscriber anymore!!! Technical story here, but it happened when Action Pack was integrated
more tightly with the Partner Program. Somehow I didn't complete the Action Pack renewal
transaction completely in February, but the partner site didn't show that (it only
showed I'm still good for the Partner Program).
</p>
        <p>
Couple of days later, I could go ahead with the migration process. It turned out to
be easier than I expected after I found a very useful document about <a href="http://www.itexpertmag.com/server/upgrading-small-business-server-2003-to-exchange-2007" target="_blank">Upgrading
Small Business Server 2003 to Exchange 2007</a>. Some pointers on using the document
though;
</p>
        <ul>
          <li>
Transferring the the other FSMO's (Schema Master is described); <a href="http://www.petri.co.il/determining_fsmo_role_holders.htm" target="_blank">Determining
FSMO Role Holders</a></li>
          <li>
With Windows Server 2008 you NEED the Exchange 2007 SP1 DVD, Exchange 2007 without
SP1 will not pass installation checks. 
</li>
          <li>
Section Migrate mail send does not cover migrate mail receive. This caused me a bit
of downtime... The issue was 
<br /><font face="Courier New">SMTP error from remote mail server after MAIL FROM:&lt;abcd@efg.hi&gt;
SIZE=2703: 
<br />
host abcdef.ghi [10.10.10.10]: 530 5.7.1 Client was not authenticated</font><br />
And can be solved in the following manner in Exchange Management Console: 
<ul><li>
Go to the Server Configuration, Hub Transport. Select your server and add Anonymous
to the Default SERVERNAME Receive Connector. While you're there, you can increase
receiving message size here too.</li></ul></li>
        </ul>
        <p>
And there were parts I did different;
</p>
        <ul>
          <li>
I continue to rely on <a href="http://www.vamsoft.com/" target="_blank">Vamsoft's
ORF</a> for the anti-spam. Version 4.3 is fully compatible with Windows Server 2008
and Exchange 2007 and an ease to configure. 
</li>
          <li>
Since I will continue the same DNS name for OWA and Windows mobile Active Sync, I
transferred the Self-signed certificate from the SBS2003 (find it in your IIS, web
site, directory security tab) to the new server.</li>
        </ul>
        <p>
My other bit of downtime was the blog... simply copy from the old server to the new
one didn't cut it. So I downloaded the latest release of <a href="http://dasblog.codeplex.com/Release/ProjectReleases.aspx" target="_blank">dasBlog
from Codeplex</a>, copied it into the virtual director of new server. Next I had to;
</p>
        <ul>
          <li>
Copy my own theme 
</li>
          <li>
Compare (and adjust) the \SiteConfig files 
</li>
          <li>
Transfer \Content files and \Logs files 
</li>
          <li>
Make sure the account running the Application Pool has read on all dasBlog folders
and change on \SiteConfig, \Content and \Logs. 
</li>
          <li>
The Application Pool is running in Classic Managed Pipeline Mode</li>
        </ul>
        <p>
Guess I can say I didn't plan for the blog to be upgraded... that just had to happen.
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=9f424662-7e1f-4f60-a7d5-ed2755ea6499" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Release 2 for SQL Server 2008 in the make</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/05/15/Release2ForSQLServer2008InTheMake.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,52a8d242-2863-4875-aac2-51794f3d529f.aspx</id>
    <published>2009-05-15T13:30:57.6158053+02:00</published>
    <updated>2009-05-15T13:30:57.6158053+02:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Microsoft launched a new preview site for <a href="http://www.microsoft.com/sqlserver/2008/en/us/r2.aspx" target="_blank">SQL
Server 2008 R2</a>. You can sign up for notifications about the releases of CTP's.
</p>
        <p>
From an administrative viewpoint, focus seems at tools to manage, utilize and consolidate
instances and machines.
</p>
        <p>
Towards usability (mainly business intelligence), enhancements to integrate with Office
2010 (mainly Excel and SharePoint) are featured. Also further integration with Virtual
Earth is shown.
</p>
        <p>
Finally there is mention about something called Master Data Services and the Stewardship
Portal. In concept a very powerful way to create and maintain a data warehouse bus.
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=52a8d242-2863-4875-aac2-51794f3d529f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Prep coaching session for 70-432 from Microsoft</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/03/24/PrepCoachingSessionFor70432FromMicrosoft.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,f9f3eb3c-f4a6-4d7a-a07d-6bd21d15973f.aspx</id>
    <published>2009-03-24T09:46:13.2750129+01:00</published>
    <updated>2009-04-02T15:45:10.1712985+02:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <category term="Train_Cert" label="Train_Cert" scheme="http://resquel.com/ssb/CategoryView,category,TrainCert.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Noticed <a title="Don't Miss Coaching Session for Exam 70-432" href="http://blogs.technet.com/mslcommunity/archive/2009/03/23/don-t-miss-coaching-session-for-exam-70-432.aspx" target="_blank">this
one on Born to Learn</a>... Microsoft has two sessions today/tomorrow on preparing
for the exam 70-432 
</p>
        <blockquote>
          <p>
Tuesday, March 24  <a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032404570&amp;Culture=en-US">7:30
A.M. Pacific Time</a>   (<a href="http://www.timeanddate.com/worldclock/fixedtime.html?month=3&amp;day=24&amp;year=2009&amp;hour=7&amp;min=30&amp;sec=0&amp;p1=234">What
time is this in my region?</a> 2009-03-24 15:30 CET)
</p>
        </blockquote>
        <blockquote>
          <p>
Tuesday, March 24  <a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032404571&amp;Culture=en-US">5:30
P.M. Pacific Time</a>   (<a href="http://www.timeanddate.com/worldclock/fixedtime.html?month=3&amp;day=24&amp;year=2009&amp;hour=17&amp;min=30&amp;sec=0&amp;p1=234">What
time is this in my region?</a> 2009-03-25 01:30 CET)
</p>
        </blockquote>
        <p>
It slipped past me too, but since I can manage to squeeze the first session in my
schedule, I'll attend. Follow up and <a href="https://www112.livemeeting.com/cc/microsoft/view?id=MCP032409-1&amp;pw=certify" target="_blank">link
to the recording</a> to be posted later.
</p>
        <p>
My impressions of this sessions is that <a href="http://robboek.com" target="_blank">Rob
Boek</a> takes you through the main areas of interest for the exam, at least it aligned
quite well with what I can remember from my beta-test. Good stuff if you need an impression
of the most important topics of the exam to prepare for.
</p>
        <p>
Updated 2009-04-02
</p>
        <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:1a4cd14a-69b6-4c82-827d-b341154c5be5" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati
tags: <a href="http://technorati.com/tags/70-432" rel="tag">70-432</a>, <a href="http://technorati.com/tags/MCTS" rel="tag">MCTS</a></div>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=f9f3eb3c-f4a6-4d7a-a07d-6bd21d15973f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Deadlock alerts through Event Notification</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/03/02/DeadlockAlertsThroughEventNotification.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,2a1df111-2a66-4919-820f-019df215381d.aspx</id>
    <published>2009-03-02T12:30:01.3001711+01:00</published>
    <updated>2010-07-24T19:04:05.758+02:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>
            <em>
              <u>Updated 2010-07-24; added timeout to the receive command in the stored
procedure. For more info, see </u>
            </em>
          </strong>
          <a title="Service Broker can make your transaction log big" href="http://resquel.com/ssb/2010/07/24/ServiceBrokerCanMakeYourTransactionLogBig.aspx" target="_blank">
            <em>
              <u>Service
Broker can make your transaction log big</u>
            </em>
          </a>
          <strong>
            <em>
              <u>.</u>
            </em>
          </strong>
        </p>
        <p>
Event Notifications are based on Service Broker. This brings an advantage and a disadvantage;
enhanced scalability at the cost of increased complexity (and lack of a User Interface,
so we have to take it to T-SQL code). Lets take it there step by step for SQL Server
2005 and 2008;
</p>
        <ol>
          <li>
Some code to cause deadlocks. 
</li>
          <li>
See how the deadlocks look like using the Trace Flags. 
</li>
          <li>
See how the deadlocks look like in Profiler. 
</li>
          <li>
Use the Event Notification on the deadlocks. 
</li>
          <li>
Sending out the mail. 
</li>
        </ol>
        <p>
The code shown as part of this article is also available at this <a title="DeadLock Event Notification script." href="http://www.resquel.com/ssb/content/upload/ReSQueLBlogPost20090302_DeadLockEventNotification.sql.txt" target="_blank">link</a>.
To code to create the database for the deadlocks is available at this <a title="DeadLockSample database script." href="http://www.resquel.com/ssb/content/upload/ReSQueLBlogPost20090302_DeadLockSample.sql.txt" target="_blank">link</a>.
The code works with SQL Server 2005 SP2 and SQL Server 2008
</p>
        <h3>1. Some code to cause deadlocks.
</h3>
        <p>
To get the code to cause the deadlocks, click this <a title="DeadLockSample database script." href="http://www.resquel.com/ssb/content/upload/ReSQueLBlogPost20090302_DeadLockSample.sql.txt" target="_blank">link</a>.
Run the code from SQL Server Management Studio (SSMS) to create the DeadLockSample
database. Next create two additional connections (New Query) to the DeadLockSample
database, execute the procedure procLockedTran1 on one connection and procLockedTran2
on the other connection. There is a 5 seconds delay in the two procedures between
locking the first and second resource. So if you execute the two procedures within
5 seconds, you get your deadlock. You could also change the delay in the procedures
if you think 5 seconds is to short/long.
</p>
        <p>
Normally a process would be terminated when it is the deadlock victim. For the procedures
created by the script, the error is handled , so the process that is the deadlock
victim just selects it is the victim and the connection will not be terminated.
</p>
        <p>
If you want to create a deadlock in any of the following scenarios, just run procLockedTran1
and procLockedTran2 on two separate connections simultaneously.
</p>
        <h3>2. See how the deadlocks look like using the Trace Flags.
</h3>
        <a href="http://www.resquel.com/ssb/content/binary/WindowsLiveWriter/DeadlockalertsthroughEventNotification_14104/TraceFlagConfiguration_2.png">
          <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="TraceFlagConfiguration" align="right" src="http://www.resquel.com/ssb/content/binary/WindowsLiveWriter/DeadlockalertsthroughEventNotification_14104/TraceFlagConfiguration_thumb.png" width="244" height="243" />
        </a>
        <p>
To get the deadlocks recorded in the SQL Server Error Log, either set the trace flag
as startup parameter in SQL Server Configuration Manager (see picture) which will
cause the trace flag to be active each time you start your SQL Server (until you remove
the trace flag again), or issue a DBCC TRACEON (1222,-1) command which sets the trace
flag until you stop SQL Server or issue a DBCC TRACEOFF (1222,-1).
</p>
        <p>
With the trace flag active, you can now see the deadlock appear in you SQL Server
Error Log.
</p>
        <h3>3. See how the deadlocks look like in Profiler.
</h3>
        <p>
... or in SSMS for that matter. With the SQL Server tools it is possible to display
deadlock graphs; XML documents (with .xdl extension) describing the deadlock information
of one or more deadlocks. When the deadlock graph event (EventClass 148) with the
TextData column is included in the trace definition, the XML to create the deadlock
graph is captured (both through the Profiler graphical tool and the sp_trace procedures)
and the graph will automatically be displayed when opened in Profiler. Also the graphical
profiler has the option to write deadlock graphs directly to a file. Note that the
graphical presentation of the deadlock is limited compared to the information in the
.xdl document. The information in the .xdl document is the same information as the
information written to the SQL Server Error Log with trace flag 1222. One extra comment
if you filter your trace on database, you won't get the deadlock graph, as <a href="http://sqlblog.com/blogs/kalen_delaney/archive/2006/11/28/376.aspx" target="_blank">noticed
by Kalen Delaney</a>.
</p>
        <h3>4. Use the Event Notification on the deadlocks.
</h3>
        <p>
Event Notification lets you capture events that can occur on server, database or broker
queue, for a list of events, query sys.event_notification_event_types. For this purpose,
the event type 1148, DEADLOCK_GRAPH is of interest. Also note that the DEADLOCK_GRAPH
is a <a href="http://msdn.microsoft.com/en-us/library/ms190655.aspx" target="_blank">trace
event</a>, which can only be captured at server level.
</p>
        <p>
The second thing needed is a broker SERVICE to send the event to. Since we'll be handling
the events at server level, the SERVICE (and QUEUE) will be created in the msdb database.
There is no need to create the MESSAGE TYPEs  or CONTRACTs as they already exist
for Event Notification.
</p>
        <blockquote>
          <p>
            <font size="2">
              <font color="#0000ff">USE</font> msdb 
<br /></font>
            <font color="#0000ff" size="2">GO 
<br /></font>
            <font size="2">
              <font color="#008000">-- Create a queue to receive messages. 
<br /></font>
              <font color="#0000ff">CREATE</font>
              <font color="#0000ff">QUEUE</font> queDeadLock_Graph</font>
            <font color="#808080" size="2">; 
<br /></font>
            <font color="#0000ff" size="2">GO 
<br /></font>
            <font size="2">
              <font color="#008000">-- Create a service on the queue that
references 
<br />
-- the event notifications contract. 
<br /></font>
              <font color="#0000ff">CREATE</font>
              <font color="#0000ff">SERVICE</font> svcDeadLock_Graph 
<br /><font color="#0000ff">ON</font><font color="#0000ff">QUEUE</font> queDeadLock_Graph 
<br /><font color="#808080">(</font>[http://schemas.microsoft.com/SQL/Notifications/PostEventNotification]</font>
            <font color="#808080" size="2">); 
<br /></font>
            <font size="2">
              <font color="#0000ff">GO 
<br /></font>
              <font color="#008000">-- Now query the sys.databases for the service_broker_guid
of the msdb database.</font>
            </font>
            <font size="2">
              <font color="#008000">
                <br />
              </font>
              <font color="#0000ff">SELECT</font> service_broker_guid <font color="#0000ff">FROM</font><font color="#008000">sys</font><font color="#808080">.</font><font color="#008000">databases</font><font color="#0000ff">WHERE</font> name <font color="#808080">=</font><font color="#ff0000">'msdb'</font><font color="#808080">;</font></font>
          </p>
        </blockquote>
        <p>
The result of the query for the Service Broker GUID for the msdb databases is needed
to point to the right database for the service.
</p>
        <blockquote>
          <p>
            <font size="2">
              <font color="#008000">-- Create the event notification. 
<br /></font>
              <font color="#0000ff">CREATE</font>
              <font color="#0000ff">EVENT</font>
              <font color="#0000ff">NOTIFICATION</font> evnDeadLock_Graph 
<br /><font color="#0000ff">ON</font><font color="#0000ff">SERVER</font><br /><font color="#0000ff">FOR</font> DEADLOCK_GRAPH 
<br /><font color="#0000ff">TO</font><font color="#0000ff">SERVICE</font></font>
            <font size="2">
              <font color="#ff0000">'svcDeadLock_Graph' 
<br /></font>
              <font color="#808080">,</font>
              <font color="#ff0000">'2A7C5300-7C64-43F5-AB10-5B079D07678E'</font>
              <font color="#808080">;</font>
              <font color="#008000">--
the GUID for msdb goes here.</font>
            </font>
            <font color="#008000" size="2">
              <br />
            </font>
          </p>
        </blockquote>
        <p>
You can look at the content of the queue through SELECT * FROM msdb.dbo.queDeadLock_Graph,
as a queue in fact is a table. Next step will be processing the messages that get
into the queue and more specifically get the deadlock details out of the message_body.
The message body looks binary, but if you query it like this;
</p>
        <blockquote>
          <p>
            <font size="2">
              <font color="#0000ff">SELECT</font>
              <font color="#ff00ff">CAST</font>
              <font color="#808080">(</font>message_body <font color="#0000ff">AS</font><font color="#0000ff">xml</font><font color="#808080">)</font><font color="#0000ff">FROM</font> msdb<font color="#808080">.</font>dbo<font color="#808080">.</font>queDeadLock_Graph</font>
            <font size="+0">
            </font>
          </p>
        </blockquote>
        <p>
you'll notice that it is actually XML, where the textdata node holds the xdl structure
of the deadlock graph.
</p>
        <h3>5. Sending out the mail
</h3>
        <p>
Okay, we're in Service Broker land by now. Event Notification acts as the Initiator
Service and the svcDeadLock_Graph is the Target Service. In this scenario, the only
thing left to be done is specify how the queue should be processed. The processing
shall be done by a stored procedure that will be tied to the queue as the activation
program. Once something comes in to the queue, this stored procedure will be invoked...
kind of like a trigger for insert on a normal table. The specification for the stored
procedure will be:
</p>
        <ol>
          <li>
Extract the deadlock graph from the message_body and store it in a variable. 
</li>
          <li>
Extract the datetime of the deadlock graph notification and store it in a variable. 
</li>
          <li>
Store the datetime and deadlock graph in a table. 
</li>
          <li>
Send the datetime as part of the message and deadlock graph as attachment in an email.
This does require database mail to be set up, if you haven't, an error will be logged
in the table. 
</li>
        </ol>
        <p>
The code to create the table to hold the deadlock information (and the reason why
no mail was sent).
</p>
        <blockquote>
          <p>
            <font size="2">
              <font color="#0000ff">USE</font> msdb 
<br /></font>
            <font size="2">
              <font color="#0000ff">GO 
<br />
CREATE</font>
              <font color="#0000ff">TABLE</font> dbo<font color="#808080">.</font>tblDeadLock_Log<font color="#0000ff"></font></font>
            <font size="2">
              <font color="#808080">( 
<br /></font>DeadLock_ID <font color="#0000ff">int</font><font color="#0000ff">IDENTITY</font><font color="#808080">(</font>1<font color="#808080">,</font>1<font color="#808080">)</font><font color="#0000ff">CONSTRAINT</font> pk_tblDeadLock_Log <font color="#0000ff">PRIMARY</font></font>
            <font size="2">
              <font color="#0000ff">KEY 
<br /></font>
              <font color="#808080">,</font> DeadLock_Detected </font>
            <font size="2">
              <font color="#0000ff">datetime 
<br /></font>
              <font color="#808080">,</font> DeadLock_Graph </font>
            <font size="2">
              <font color="#0000ff">xml 
<br /></font>
              <font color="#808080">,</font> NoMailReason <font color="#0000ff">nvarchar</font><font color="#808080">(</font>2048</font>
            <font color="#808080" size="2">)) 
<br /></font>
            <font color="#0000ff">
              <font size="2">GO</font>
              <br />
            </font>
          </p>
        </blockquote>
        <p>
The stored procedure to be used as the activation program on the queue, this is where
the real work is done. Alter the @profile_name and @recipients in at sp_send_dbmail
to match the setup of your dbmail setup.
</p>
        <blockquote>
          <p>
            <font size="2">
              <font color="#0000ff">CREATE</font>
              <font color="#0000ff">PROCEDURE</font> dbo<font color="#808080">.</font>procReceiveDeadLock_Graph 
<br /></font>
            <font size="2">
              <font color="#0000ff">AS 
<br />
DECLARE</font> @conversation_handle </font>
            <font size="2">
              <font color="#0000ff">uniqueidentifier 
<br />
DECLARE</font> @message_body </font>
            <font size="2">
              <font color="#0000ff">xml 
<br />
DECLARE</font> @message_type_name <font color="#0000ff">nvarchar</font><font color="#808080">(</font>128</font>
            <font size="2">
              <font color="#808080">) 
<br /></font>
              <font color="#0000ff">DECLARE</font> @deadlock_graph </font>
            <font size="2">
              <font color="#0000ff">xml 
<br />
DECLARE</font> @event_datetime </font>
            <font size="2">
              <font color="#0000ff">datetime 
<br />
DECLARE</font> @deadlock_id </font>
            <font size="2">
              <font color="#0000ff">int 
<br />
BEGIN</font>
            </font>
            <font size="2">
              <font color="#0000ff">TRY 
<br />
BEGIN</font>
            </font>
            <font color="#0000ff" size="2">TRAN 
<br />
WAITFOR</font>
            <font size="2">
              <font color="#808080">( 
<br /></font>
              <font color="#0000ff">RECEIVE</font>
              <font color="#0000ff">TOP</font>
              <font color="#808080">(</font>1<font color="#808080">)</font> @conversation_handle <font color="#808080">=</font></font>
            <font size="2">
              <font color="#0000ff">conversation_handle 
<br /></font>
              <font color="#808080">,</font> @message_body <font color="#808080">=</font><font color="#ff00ff">CAST</font><font color="#808080">(</font>message_body <font color="#0000ff">AS</font><font color="#0000ff">xml</font></font>
            <font size="2">
              <font color="#808080">) 
<br />
,</font> @message_type_name <font color="#808080">=</font> message_type_name 
<br /><font color="#0000ff">FROM</font> dbo<font color="#808080">.</font>queDeadLock_Graph<font color="#808080">)</font></font>
            <font color="#808080">
              <font size="2">
                <br />
, <font color="#0000ff">TIMEOUT </font><font color="#808080">10000 </font></font>
              <font size="2">
                <font color="#008000">--
Line added 2010-07-24; 
<br />
-- http://resquel.com/ssb/2010/07/24/ServiceBrokerCanMakeYourTransactionLogBig.aspx </font>
                <br />
              </font>
            </font>
            <font size="2">
              <font color="#008000">-- Validate message 
<br /></font>
              <font color="#0000ff">IF </font>
              <font color="#808080">(</font>@message_type_name <font color="#808080">=</font><font color="#ff0000">'http://schemas.microsoft.com/SQL/Notifications/EventNotification'</font></font>
            <font size="2">
              <font color="#808080">AND 
<br /></font>@message_body<font color="#808080">.</font>exist<font color="#808080">(</font><font color="#ff0000">'(/EVENT_INSTANCE/TextData/deadlock-list)'</font><font color="#808080">)</font><font color="#808080">=</font> 1</font>
            <font color="#808080" size="2">) 
<br /></font>
            <font color="#0000ff" size="2">BEGIN 
<br /></font>
            <font size="2">
              <font color="#008000">-- Extract the info from the message 
<br /></font>
              <font color="#0000ff">SELECT</font> @deadlock_graph <font color="#808080">=</font> @message_body<font color="#808080">.</font>query<font color="#808080">(</font><font color="#ff0000">'(/EVENT_INSTANCE/TextData/deadlock-list)'</font></font>
            <font size="2">
              <font color="#808080">) 
<br />
,</font> @event_datetime <font color="#808080">= </font>@message_body<font color="#808080">.</font>value<font color="#808080">(</font><font color="#ff0000">'(/EVENT_INSTANCE/PostTime)[1]'</font><font color="#808080">,</font><font color="#ff0000">'datetime'</font></font>
            <font color="#808080" size="2">) 
<br /></font>
            <font size="2">
              <font color="#008000">-- Put the info in the table 
<br /></font>
              <font color="#0000ff">INSERT</font> dbo<font color="#808080">.</font>tblDeadLock_Log<font color="#0000ff"></font><font color="#808080">(</font>DeadLock_Detected<font color="#808080">,</font> DeadLock_Graph</font>
            <font size="2">
              <font color="#808080">) 
<br /></font>
              <font color="#0000ff">VALUES </font>
              <font color="#808080">(</font>@event_datetime<font color="#808080">,</font> @deadlock_graph</font>
            <font size="2">
              <font color="#808080">) 
<br /></font>
              <font color="#0000ff">SELECT</font> @deadlock_id <font color="#808080">=</font><font color="#ff00ff">SCOPE_IDENTITY</font></font>
            <font color="#808080" size="2">() 
<br /></font>
            <font size="2">
              <font color="#008000">-- Send deadlock alert mail. 
<br />
-- Requires configured database mail, will log an error if not (or anything else goes
wrong). 
<br /></font>
              <font color="#0000ff">BEGIN</font>
            </font>
            <font size="2">
              <font color="#0000ff">TRY 
<br /></font>
              <font color="#0000ff">DECLARE</font> @subj <font color="#0000ff">nvarchar</font><font color="#808080">(</font>255<font color="#808080">),</font> @bdy <font color="#0000ff">nvarchar</font><font color="#808080">(</font><font color="#ff00ff">max</font><font color="#808080">),</font> @qry <font color="#0000ff">nvarchar</font><font color="#808080">(</font><font color="#ff00ff">max</font><font color="#808080">),</font> @attfn <font color="#0000ff">nvarchar</font><font color="#808080">(</font>255</font>
            <font size="2">
              <font color="#808080">) 
<br /></font>
              <font color="#0000ff">SELECT</font> @subj <font color="#808080">=</font><font color="#ff0000">'A
deadlock occurred on '</font><font color="#808080">+</font></font>
            <font size="2">
              <font color="#ff00ff">@@SERVERNAME 
<br /></font>
              <font color="#808080">,</font> @bdy <font color="#808080">=</font><font color="#ff0000">'A
deadlock occurred at '</font><font color="#808080">+</font><font color="#ff00ff">CONVERT</font><font color="#808080">(</font><font color="#0000ff">varchar</font><font color="#808080">(</font>50<font color="#808080">),</font>@event_datetime<font color="#808080">,</font> 120<font color="#808080">)</font><font color="#808080">+</font><font color="#ff0000">'
on SQL Server: '</font><font color="#808080">+</font><font color="#ff00ff">@@SERVERNAME</font><font color="#808080">+</font></font>
            <font size="2">
              <font color="#ff0000">'.
See attached xdl-file for deadlock details.' 
<br /></font>
              <font color="#808080">,</font> @qry <font color="#808080">=</font><font color="#ff0000">'SET
NOCOUNT ON; SELECT deadlock_graph FROM msdb.dbo.tblDeadLock_Log WITH (READUNCOMMITTED)
WHERE DeadLock_ID = '</font><font color="#808080">+</font><font color="#ff00ff">CAST</font><font color="#808080">(</font>@deadlock_id <font color="#0000ff">AS</font><font color="#0000ff">varchar</font><font color="#808080">(</font>10</font>
            <font size="2">
              <font color="#808080">)) <font color="#008000">--
Locking hint is to prevent this dynamic query to be blocked by the lock held by the
insert. The dynamic SQL will not come from inside this transaction.</font><br /></font>
              <font color="#808080">,</font> @attfn <font color="#808080">=</font><font color="#ff00ff">@@SERVERNAME</font><font color="#808080">+</font><font color="#ff0000">'_'</font><font color="#808080">+</font><font color="#ff00ff">CAST</font><font color="#808080">(</font>@deadlock_id <font color="#0000ff">AS</font><font color="#0000ff">varchar</font><font color="#808080">(</font>10<font color="#808080">))</font><font color="#808080">+</font></font>
            <font size="2">
              <font color="#ff0000">'.xdl' 
<br /></font>
              <font color="#0000ff">EXEC</font>
              <font color="#800000">sp_send_dbmail</font>
              <font color="#0000ff">
              </font>@profile_name <font color="#808080">=</font></font>
            <font size="2">
              <font color="#ff0000">'default' 
<br /></font>
              <font color="#808080">,</font> @recipients <font color="#808080">=</font></font>
            <font size="2">
              <font color="#ff0000">'administrator@localhost' 
<br /></font>
              <font color="#808080">,</font> @subject <font color="#808080">=</font> @subj 
<br /><font color="#808080">,</font> @body <font color="#808080">=</font> @bdy 
<br /><font color="#808080">,</font> @query <font color="#808080">=</font> @qry 
<br /><font color="#808080">,</font> @attach_query_result_as_file <font color="#808080">=</font> 1 
<br /><font color="#808080">,</font> @query_attachment_filename <font color="#808080">=</font> @attfn </font>
            <font size="2">
              <font color="#008000">--
http://support.microsoft.com/kb/924345 
<br /></font>
              <font color="#808080">,</font> @query_result_header <font color="#808080">=</font> 0 
<br /><font color="#808080">,</font> @query_result_width <font color="#808080">=</font> 32767 
<br /><font color="#808080">,</font> @query_no_truncate <font color="#808080">=</font> 1 
<br /><font color="#0000ff">END</font></font>
            <font size="2">
              <font color="#0000ff">TRY 
<br /></font>
              <font color="#0000ff">BEGIN</font>
            </font>
            <font size="2">
              <font color="#0000ff">CATCH 
<br /></font>
              <font color="#0000ff">UPDATE</font> dbo<font color="#808080">.</font>tblDeadLock_Log 
<br /><font color="#0000ff">SET</font> NoMailReason <font color="#808080">=</font><font color="#ff00ff">ERROR_MESSAGE</font></font>
            <font size="2">
              <font color="#808080">() 
<br /></font>
              <font color="#0000ff">WHERE</font> DeadLock_ID <font color="#808080">=</font> @deadlock_id 
<br /><font color="#0000ff">END</font></font>
            <font size="2">
              <font color="#0000ff">CATCH 
<br />
END 
<br />
ELSE <font color="#008000">-- Not an event notification with deadlock-list</font><br />
END</font>
              <font color="#0000ff">CONVERSATION</font> @conversation_handle 
<br /><font color="#0000ff">COMMIT</font></font>
            <font size="2">
              <font color="#0000ff">TRAN 
<br />
END</font>
            </font>
            <font size="2">
              <font color="#0000ff">TRY 
<br />
BEGIN</font>
            </font>
            <font size="2">
              <font color="#0000ff">CATCH 
<br />
ROLLBACK</font>
            </font>
            <font size="2">
              <font color="#0000ff">TRAN 
<br />
END</font>
            </font>
            <font color="#0000ff" size="2">CATCH 
<br />
GO 
<br /></font>
          </p>
        </blockquote>
        <p>
Finally to tie the stored procedure to the queue so incoming notifications will be
processed.
</p>
        <blockquote>
          <p>
            <font size="2">
              <font color="#0000ff">ALTER</font>
              <font color="#0000ff">QUEUE</font> dbo<font color="#808080">.</font>queDeadLock_Graph 
<br /></font>
            <font size="2">
              <font color="#0000ff">WITH 
<br />
STATUS</font>
              <font color="#808080">=</font>
              <font color="#0000ff">ON</font>
            </font>
            <font size="2">
              <font color="#808080">, 
<br /></font>
              <font color="#0000ff">ACTIVATION </font>
            </font>
            <font size="2">
              <font color="#808080">( 
<br /></font>
              <font color="#0000ff">PROCEDURE_NAME</font>
              <font color="#808080">=</font> msdb<font color="#808080">.</font>dbo<font color="#808080">.</font>procReceiveDeadLock_Graph</font>
            <font size="2">
              <font color="#808080">, 
<br /></font>
              <font color="#0000ff">STATUS</font>
              <font color="#808080">=</font>
              <font color="#0000ff">ON</font>
            </font>
            <font size="2">
              <font color="#808080">, 
<br /></font>
              <font color="#0000ff">MAX_QUEUE_READERS</font>
              <font color="#808080">=</font> 1</font>
            <font size="2">
              <font color="#808080">, 
<br /></font>
              <font color="#0000ff">EXECUTE</font>
              <font color="#0000ff">AS</font>
              <font color="#0000ff">OWNER</font>
            </font>
            <font color="#808080" size="2">) 
<br /></font>
            <font color="#0000ff">
              <font size="2">GO</font>
            </font>
          </p>
        </blockquote>
        <p>
Now try the procedures procLockedTran1 and procLockedTran2 and see the results in
the msdb.dbo.tblDeadLock_Log and in your mail (if configured).
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=2a1df111-2a66-4919-820f-019df215381d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Alert me (on deadlocks)</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/02/27/AlertMeOnDeadlocks.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,c63b8f8e-06e5-42cc-bfdb-f9ea8b76adbc.aspx</id>
    <published>2009-02-27T22:47:32.1447853+01:00</published>
    <updated>2009-04-08T23:21:12.4311139+02:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Okay, here's the deal; deadlocks sometimes occur and you want to be notified as they
happen.
</p>
        <p>
So define an SQL Agent Alert on error 1205 to send you an e-mail notification... partially,
but it won't work as error 1205 isn't logged.
</p>
        <p>
How to get the error logged; either set the severity level to 19 or above when the
message is created (does not apply to 1205) or flag the message to be logged to event
log, which can be done using sp_altermessage... at least this was the way to do it
with SQL Server 2000 but one of the changes for SQL Server 2005 says:
</p>
        <blockquote>
          <p>
            <b>sp_altermessage</b> cannot be used to change the logging behavior of system messages
(messages with Message ID &lt; 50000). To audit system messages, use SQL Trace and
the <a href="http://msdn.microsoft.com/en-us/library/ms190953(SQL.90).aspx" target="_blank">User
Error Message Event Class</a>. For more information, see <a href="http://msdn.microsoft.com/en-us/library/ms191006(SQL.90).aspx" target="_blank">Introducing
SQL Trace</a>.
</p>
        </blockquote>
        <p>
For SQL Server 2005 it used to be a dead end, but with as of Service Pack 3 it is
again possible to alter sys.messages &lt; 50000 so they are written to the Windows
NT Application Event Log. Specifically for deadlocks you'd run:
</p>
        <blockquote>
          <p>
EXEC sp_altermessage 1205, 'WITH_LOG', 'true'
</p>
        </blockquote>
        <p>
but it would apply to other system events you want logged too.
</p>
        <p>
Update 2009-04-08; issue fixed in Service Pack 1 for SQL Server 2008. <strike>For
SQL Server 2008 (up until Cumulative Update 3) it is still impossible to alter sys.messages
&lt; 50000. Though it was mentioned (2008-07-28) at connect in </strike><a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=294122" target="_blank"><strike>FeedBackID=294122</strike></a><strike> that
this issue would be fixed for SQL Server 2008 too, so far (2009-02-27) it isn't.</strike></p>
        <p>
          <strike>Besides the fact that the alert option is still impossible with SQL Server
2008,</strike> it can only tell you a deadlock occurred. Should you need more information
on the deadlock however, your next option would be <a href="http://msdn.microsoft.com/en-us/library/ms188396(SQL.90).aspx" target="_blank">TRACE
flags</a> 1204 or 1222, the difference between the two of them being the amount of
detail. Trace flag 1222 will be use during the post as it provides the most detail.
Setting the trace flags writes the deadlock information to the SQL Server Error Log,
but not to the Windows NT Application Event Log... so there's <strike>one</strike> two
(and a half) option remaining:
</p>
        <blockquote>
          <p>
Process the Error Log with the undocumented sp_readerrorlog as part of the alert response...
but that won't work for SQL Server 2008 (yet) and you have a better option for SQL
Server 2005. For more info see <a href="http://www.mssqltips.com/tip.asp?tip=1476" target="_blank">MSSQLTips</a>.
</p>
          <p>
SQL Server 2005 &amp; 2008: <a title="Deadlock alerts through Event Notification" href="http://www.resquel.com/ssb/2009/03/02/DeadlockAlertsThroughEventNotification.aspx" target="_blank">Event
Notification</a></p>
          <p>
SQL Server 2005 &amp; 2008: WMI Alert, see <a href="http://msdn.microsoft.com/en-us/library/ms186385(SQL.90).aspx" target="_blank">MSDN</a></p>
        </blockquote>
        <p>
So next post will be on getting your <a title="Deadlock alerts through Event Notification" href="http://www.resquel.com/ssb/2009/03/02/DeadlockAlertsThroughEventNotification.aspx" target="_blank">deadlock
info through Event Notification</a>.
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=c63b8f8e-06e5-42cc-bfdb-f9ea8b76adbc" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Relog Syntax Examples (for SQL Server)</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/02/26/RelogSyntaxExamplesForSQLServer.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,0876cb3c-5319-4580-819b-cda4be6dddb2.aspx</id>
    <published>2009-02-26T15:42:13.1312451+01:00</published>
    <updated>2009-02-26T15:49:00.2197913+01:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <category term="Vista" label="Vista" scheme="http://resquel.com/ssb/CategoryView,category,Vista.aspx" />
    <category term="Windows Server 2008" label="Windows Server 2008" scheme="http://resquel.com/ssb/CategoryView,category,WindowsServer2008.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
As I <a href="http://www.resquel.com/ssb/2008/11/24/RelogSQLDatabaseSchemaNastyDatetimeHandling.aspx" target="_blank">blogged
before</a>, relog is quite useful. The <a href="http://technet.microsoft.com/en-us/library/bb490958.aspx" target="_blank">syntax
examples on the TechNet</a> page however are pretty much useless if you want to go
to SQL Server. So let's look at a few scenarios and the syntax to make them work,
but before that, let's get the DSN and the counter data file.
</p>
        <p>
Configure the Data Source Name to the SQL Server as System DSN based on the SQL Server
driver (SQLSRV32.DLL)... Native Client does NOT work. The name of the DSN in the syntax
samples will be <strong>PerfDB</strong>.
</p>
        <p>
Next is the file with performance data. Relog will detect the format from its internal
structure (if it is a valid counter log file), so you do not have to specify if your
file is comma separated (.csv), tab separated (.tsv) or binary (.blg). Since binary
is the most practical format for large amounts of data, the file for the syntax examples
will be <strong>c:\my perflogs\p_log01.blg </strong>(and consecutive numbers for any
next file).
</p>
        <p>
One final comment before going to the scenarios; relog creates three tables in the
SQL Server database targeted by the DSN (if they do not already exist). These tables
are;<a href="http://www.resquel.com/ssb/content/binary/WindowsLiveWriter/RelogSyntaxSamplesforSQLServer_9408/relog_schema_2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="223" alt="relog_schema" src="http://www.resquel.com/ssb/content/binary/WindowsLiveWriter/RelogSyntaxSamplesforSQLServer_9408/relog_schema_thumb.png" width="244" align="right" border="0" /></a></p>
        <ul>
          <li>
dbo.CounterData (holds the actual values of the counter) 
</li>
          <li>
dbo.CounterDetails (holds the machine, object, counter and, if applicable, the instance) 
</li>
          <li>
dbo.DisplayToID (holds information on the perfmon data that was loaded)</li>
        </ul>
        <h3>Senario 1: Load all counters into the database
</h3>
        <blockquote>
          <p>
relog "<strong>c:\my perflogs\p_log01.blg</strong>" -f SQL -o SQL:<strong>PerfDB</strong>!<font color="#0000ff">1stRun</font></p>
        </blockquote>
        <p>
All clear, except for the blue 1stRun (and the exclamation mark preceding it). The
reason is that it is possible to write multiple logs to the same database. Each time
log information is written to the database, a new DisplayToID record is created. The
name given in blue is the  DisplayString. If the DisplayString is used before,
the data will be added under the same GUID.
</p>
        <h3>Scenario 2: Load all counters between begin and end datetime into the database
</h3>
        <blockquote>
          <p>
relog "c:\my perflogs\p_log02.blg" -f SQL -o SQL:PerfDB!2ndRun -b <strong>26-02-2009
10:00:00</strong> -e <strong>26-02-2009 10:30:00</strong></p>
        </blockquote>
        <p>
TechNet says the format for relog date times should be <em>M/d/yyyy</em><em>hh:mm:ss</em>,
which is the internal format of the log files is M/d/yyyy hh:mm:ss.sss, minus the
milliseconds. <font color="#ff0000"><strong>In reality, relog looks at the regional
settings, including the customizations you did to the regional settings!</strong></font> The
string in the sample is valid for the regional settings Dutch (Netherlands), so dd-mm-yyyy
HH:mm:ss. Best way to find out what format relog expects is to run relog /?. 
</p>
        <p>
Together with the <a href="http://www.resquel.com/ssb/2008/11/24/RelogSQLDatabaseSchemaNastyDatetimeHandling.aspx" target="_blank">previous
issue</a> of the char(24) storage of a binary converted datetime string, this regional
settings dependency is horrible handling of datetime. For globalization support it
would be great if relog was given an extra switch to indicate that datetime strings
are in ISO 8601 or ODBC format, independent of the regional setting. 
</p>
        <h3>Scenario 3: Load a limited set of counters into the database
</h3>
        <blockquote>
          <p>
relog "c:\my perflogs\p_log03.blg" -q -o c:\counters.txt
</p>
        </blockquote>
        <p>
Edit the c:\counters.txt file to only include the counters to be written to the database.
</p>
        <blockquote>
          <p>
relog "c:\my perflogs\p_log03.blg" -cf c:\counters.txt -f SQL -o SQL:PerfDB!"select
set of counters from the 3rd run"
</p>
        </blockquote>
        <p>
It is possible to combine scenarios 2 and 3 to load a limited set of counters between
two datetimes. Also, if you want spaces in the DisplayString, it can be done with
the double quotes as shown in this example.
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=0876cb3c-5319-4580-819b-cda4be6dddb2" />
      </div>
    </content>
  </entry>
  <entry>
    <title>MOC courses and VHD</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2009/01/31/MOCCoursesAndVHD.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,d4b125af-ce80-44fd-b0ba-397d2963e92c.aspx</id>
    <published>2009-01-31T18:53:43.9125812+01:00</published>
    <updated>2009-01-31T18:53:43.9125812+01:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <category term="Train_Cert" label="Train_Cert" scheme="http://resquel.com/ssb/CategoryView,category,TrainCert.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A common question for students during/after attending a Microsoft training: "Where
do we get the virtual PC images we used during course?"
</p>
        <p>
The answer is, you don't... Microsoft provides these images for classroom use only
by Certified Partners for Learning Solutions and Microsoft Certified Trainers. Quite
understandable, as these images, contain a lot of software. However, the students
question is valid too, for practice and exam preparation. And you can get about the
same experience you had in class, based on Microsoft's "<a href="http://technet.microsoft.com/en-us/bb738372.aspx" target="_blank">Run
IT on a Virtual Hard Disk</a>" program. Run IT on a Virtual Hard Disk allows you to
download and use a fully installed evaluation version of an installed product. So
here is how you can build your own VHD for the 2779 or 2780 courses.
</p>
        <ol>
          <li>
Your PC; I recommend you use a PC with at least 1.5 GB of RAM and Windows XP. 
</li>
          <li>
Virtual PC; download and install Virtual PC 2007 (if you want, you can use Virtual
Server 2005 R2 instead). For the download and more information see the <a href="http://www.microsoft.com/windows/products/winfamily/virtualpc/default.mspx" target="_blank">Microsoft
Virtual PC site</a>. 
</li>
          <li>
SQL Server VHD; download the 4 files image files for the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7b243252-acb7-451b-822b-df639443aeaf" target="_blank">SQL
Server 2005 Evaluation VHD</a> and unpack the VHD. SQL Server 2005 is currently not
listed on the <a href="http://technet.microsoft.com/en-us/bb738372.aspx" target="_blank">Run
IT on a Virtual Hard Disk site</a>. 
</li>
          <li>
SQL Server installation media; download the <a href="http://technet.microsoft.com/en-us/bb738031.aspx" target="_blank">Evaluation
Edition of SQL Server 2005</a> (180-day version), requires Windows Live ID. Some labs/practices/demonstrations
require multiple instances, these are installed on the 2779 and 2780 images, but not
on the Evaluation VHD. So you may need to install the SQLINSTANCE2 and SQLINSTANCE3. 
</li>
          <li>
SQL Service Pack; the VHD for SQL Server Evaluation has no Service Pack for SQL Server
applied, whereas the MOC courses 2779 and 2780 are based on SQL Server 2005 SP1. Links
to the SQL Server 2005 Service Packs: 
<ol><li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=cb6c71ea-d649-47ff-9176-e7cac58fd4bc&amp;displaylang=en" target="_blank">SQL
Server 2005 Service Pack 1</a></li><li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=d07219b2-1e23-49c8-8f0c-63fa18f26d3a" target="_blank">SQL
Server 2005 Service Pack 2</a></li><li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ae7387c3-348c-4faa-8ae5-949fdfbe59c4" target="_blank">SQL
Server 2005 Service Pack 3</a></li></ol></li>
          <li>
Create a Virtual machine in Virtual PC based on the downloaded VHD. Set the amount
of memory to at least 1024 MB, also enable undo disks. 
</li>
          <li>
Start and log in to the Virtual PC guest, you will need the administrator password <strong><font color="#0000ff">Evaluation1</font></strong>.
You will notice that the Windows Server 2003 operating system is not activated, therefor
you only have a limited period for evaluation. 
</li>
          <li>
From the student CD that came with your courseware, run Allfiles.exe. This will extract
all files required by the practices, labs and demonstrations. Note that the setup
will be different from what you were used to during the course. The files in the course
were on a separate VHD for each module, which was mounted as D:\. After unpacking
Allfiles.exe the whole course is in one folder tree (typically C:\Program Files\Microsoft
Learning\27xx\). Note that you may have to compensate for paths and server names;
so when you are in 2780 module 4, a path D:\democode\SalesCert.cer should be changes
to C:\Program Files\Microsoft Learning\2780\Mod04\SalesCert.cer. Likewise the name
of the server is different too, so MIAMI should be changed to WIN2K3R2EE. 
</li>
        </ol>
        <p>
Tips about downloading and file interaction between the Virtual PC host, the Guest
and the Internet.
</p>
        <ol>
          <li>
When you have a ISO-file on your host, you can mount this ISO as CD/DVD in the guest.
You can also instruct Virtual PC guest to use the CD/DVD drive from the host. 
</li>
          <li>
When you have normal files on your host, you can use the Virtual PC Shared Folders
feature; this exposes a folder on the host as a network drive on the guest. 
</li>
          <li>
You can use the Networking feature of Virtual PC to use Shared networking (NAT) or
your hosts Network adapter to allow access to the network and to Internet, so you
can download files directly into your Virtual PC guest.</li>
        </ol>
        <p>
Main differences between the MOC and Eval VHD's
</p>
        <table cellspacing="0" cellpadding="2" border="0">
          <tbody>
            <tr>
              <td valign="top">
 </td>
              <td valign="top">
MOC</td>
              <td valign="top">
Eval</td>
            </tr>
            <tr>
              <td valign="top">
Server name</td>
              <td valign="top">
MIAMI</td>
              <td valign="top">
Win2k3R2EE</td>
            </tr>
            <tr>
              <td valign="top">
SQL Server Edition</td>
              <td valign="top">
Developer SP1</td>
              <td valign="top">
Enterprise no SP</td>
            </tr>
            <tr>
              <td valign="top">
Instances</td>
              <td valign="top">
[default]<br />
SQLINSTANCE2<br />
SQLINSTANCE3</td>
              <td valign="top">
[default]</td>
            </tr>
            <tr>
              <td valign="top">
SQL Service Account</td>
              <td valign="top">
MIAMI\SQLServer</td>
              <td valign="top">
[LocalSystem]</td>
            </tr>
            <tr>
              <td valign="top">
Password</td>
              <td valign="top">
Pa$$w0rd</td>
              <td valign="top">
Evaluation1</td>
            </tr>
            <tr>
              <td valign="top">
Course files</td>
              <td valign="top">
One VHD per module</td>
              <td valign="top">
All files in a folder tree, paths have to be checked/changes.</td>
            </tr>
          </tbody>
        </table>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=d4b125af-ce80-44fd-b0ba-397d2963e92c" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Relog SQL database schema (nasty datetime handling)</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2008/11/24/RelogSQLDatabaseSchemaNastyDatetimeHandling.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,696c8d5a-223b-4d9b-9d6d-06c371483eea.aspx</id>
    <published>2008-11-24T20:48:37.9284261+01:00</published>
    <updated>2009-03-04T14:29:06.2619995+01:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
For those of you who are not familiar with the tool <a href="http://technet.microsoft.com/en-us/library/bb490958.aspx" target="_blank">Relog</a>;
it is part of Windows and allows you to reprocess System Monitor logs. This is quite
useful, as logging counters to the binary format (.blg) is very space efficient. However
to analyze those counters, you may want to use SQL Server. Relog allows to rewrite
the log and also creates the tables for you on SQL Server, if not yet present (<a href="http://www.resquel.com/ssb/2009/02/26/RelogSyntaxExamplesForSQLServer.aspx" target="_blank">syntax
samples</a>). The unfortunate part is in the CounterDateTime column of the CounterData
table, despite the column name, the date type is char(24). When trying to convert
the char(24) to a datetime, this throws the error;
</p>
        <blockquote>
          <p>
            <font color="#ff0000">Msg 241, Level 16, State 1, Line 2<br />
Conversion failed when converting datetime from character string.</font>
          </p>
        </blockquote>
        <p>
I was getting a bit annoyed by this error, as a conversion from a char to a datetime
should succeed if the string is valid... and say 2008-09-30 12:10:15.322 looked valid.
I even checked <a href="http://www.karaszi.com/SQLServer/info_datetime.asp" target="_blank">Tibors
ultimate datetime guide</a> to see if I missed something, because I was unsure of
the impact of the last byte (a valid string yyyy-mm-dd HH:mi:ss.sss actually is 23
characters). Also when trying to insert a string with a valid datetime in a variable,
the conversion succeeds. Next I turned my attention to how the data was stored in
the CounterDateTime column, by inserting a valid datetime string and retrieving one
that was inserted by Relog (both returning the string (char(24)) and its binary representation
varbinary(24)).
</p>
        <blockquote>
          <table cellspacing="0" cellpadding="2" border="0">
            <tbody>
              <tr>
                <td valign="top">
                  <strong>Source</strong>
                </td>
                <td valign="top">
                  <strong>Character representation</strong>
                </td>
                <td valign="top">
                  <strong>Binary representation</strong>
                </td>
              </tr>
              <tr>
                <td valign="top">
Relog insert</td>
                <td valign="top">
2008-09-30 12:10:15.322 
</td>
                <td valign="top">
0x323030382D30392D33302031323A31303A31352E333232<strong><font color="#ff0000">00</font></strong></td>
              </tr>
              <tr>
                <td valign="top">
Manual insert</td>
                <td valign="top">
2008-09-30 12:10:15.322 
</td>
                <td valign="top">
0x323030382D30392D33302031323A31303A31352E333232<font color="#ff0000"><strong>20</strong></font></td>
              </tr>
            </tbody>
          </table>
        </blockquote>
        <p>
The difference is in the last byte of the binary representation, the datetime string
written by relog isn't padded with spaces as one would expect to happen for the unused
positions in a char. Instead it is zeroed as one would expect for unused bytes in
a binary string. To get a datetime representation of the CounterDateTime a double
conversion is needed; 
</p>
        <blockquote>
          <p>
CAST(SUBSTRING([CounterDateTime],1,23) AS datetime)
</p>
        </blockquote>
        <p>
Now for the "nasty" in Relogs database schema:
</p>
        <ul>
          <li>
Changing the CounterDateTime to datetime is a no-go. Relog does not want it. 
</li>
          <li>
Adding a computed column with the conversions above is a no-go. Relog does not have
all columns bound.</li>
        </ul>
        <p>
What remains is creating a view on top of the CounterData table with this conversion
included.
</p>
        <p>
Another issue that may save you some time, the DSN you create to access the SQL Server
should be the "SQL Server" provider, not the "SQL Native Client".
</p>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=696c8d5a-223b-4d9b-9d6d-06c371483eea" />
      </div>
    </content>
  </entry>
  <entry>
    <title>sp_ behavior (sp_MS_marksystemobject)</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2008/10/08/spBehaviorSpMSmarksystemobject.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,bcfa2a46-377e-4a0d-8041-27dea9bc90b2.aspx</id>
    <published>2008-10-08T17:51:28.6758502+02:00</published>
    <updated>2008-10-08T17:51:28.6758502+02:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
A while back, <a href="http://www.resquel.com/ssb/PermaLink,guid,90d0dea0-2c46-4c16-975d-38e2f144410d.aspx" target="_blank">I
wrote</a> about using sp_ procedures in master to create a toolbox, which works fine
for me... until recently I hit a strange problem. I developed a procedure that would
read the definition of a table and would create a change_log table and trigger to
populate that table. On my dev-environment (Windows Vista x64, SQL Server 2005 Dev
Ed x64 SP2) this worked like I expected. But when I tested the procedure on a different
server, it didn't!?! A very little sample that touches the essence of the problem
I witnessed;
</p>
        <blockquote>
          <p>
            <font size="4">
              <font face="Courier New">
                <font color="#0000ff">use</font>
              </font>
            </font>
            <font size="4">
              <font face="Courier New">
                <font color="#0000ff">master<br />
go<br />
if</font>
                <font color="#ff00ff">object_id</font>
                <font color="#808080">(</font>
                <font color="#ff0000">'sp_test'</font>
                <font color="#808080">,</font>
                <font color="#ff0000">'p'</font>
                <font color="#808080">)</font>
                <font color="#808080">is</font>
                <font color="#808080">not</font>
              </font>
            </font>
            <font size="4">
              <font face="Courier New">
                <font color="#808080">null<br /></font>
                <font color="#0000ff">drop</font>
                <font color="#0000ff">procedure</font> sp_test<br /></font>
            </font>
            <font size="4">
              <font face="Courier New">
                <font color="#0000ff">go<br />
create</font>
                <font color="#0000ff">procedure</font> sp_test<br /></font>
            </font>
            <font size="4">
              <font face="Courier New">
                <font color="#0000ff">as<br />
select</font>
                <font color="#ff00ff">db_name</font>
                <font color="#808080">() +</font>
                <font color="#ff0000">'.'</font>
                <font color="#808080">+</font> table_schema <font color="#808080">+</font><font color="#ff0000">'.'</font><font color="#808080">+</font> table_name 
<br /><font color="#0000ff">from</font><font color="#008000">information_schema</font><font color="#808080">.</font></font>
            </font>
            <font size="4">
              <font face="Courier New">
                <font color="#008000">tables<br /></font>
                <font color="#0000ff">order</font>
                <font color="#0000ff">by</font> table_schema<font color="#808080">,</font> table_name<br /></font>
            </font>
            <font size="4">
              <font face="Courier New">
                <font color="#0000ff">go<br />
exec</font> sp_test<br /></font>
            </font>
            <font size="4">
              <font face="Courier New">
                <font color="#0000ff">go<br />
use</font> adventureworks<br /></font>
            </font>
            <font size="4">
              <font face="Courier New">
                <font color="#0000ff">go<br />
exec</font> sp_test<br /></font>
            </font>
            <font size="4">
              <font face="Courier New">
                <font color="#0000ff">go<br />
use</font>
              </font>
            </font>
            <font size="4">
              <font face="Courier New">
                <font color="#0000ff">master<br />
go<br />
drop</font>
                <font color="#0000ff">procedure</font> sp_test<br /></font>
            </font>
            <font face="Courier New" color="#0000ff" size="4">go
</font>
          </p>
        </blockquote>
        <p>
Now on my dev machine, this once listed all tables in master and once all tables in
AdventureWorks, as intended. But on other servers, it returned the tables from master
on both executions of sp_test (the db_name function is executed correctly in both
cases; once master, once AdventureWorks). For some reason, when referencing objects,
the stored procedure stayed to master. I was puzzled, but before crying BUG (out loud)
I tried the <a href="news://msnews.microsoft.com/microsoft.public.sqlserver.server" target="_blank">newsgroups</a> and
a prompt reply from SQL Server MVP Roy Harvey pointed me to the undocumented stored
procedure <strong>sp_MS_marksystemobject</strong>. Simply execute; 
</p>
        <blockquote>
          <p>
            <font color="#0000ff">exec</font> sp_MS_marksystemobject sp_test 
</p>
        </blockquote>
        <p>
and you won't suffer from the inconsistent behavior I witnessed.
</p>
        <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d0321eca-df46-4bb8-a1d0-4083c6c8a2e9" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati
tags: <a href="http://technorati.com/tags/SQL%20Server" rel="tag">SQL Server</a>, <a href="http://technorati.com/tags/Stored%20Procedure" rel="tag">Stored
Procedure</a></div>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=bcfa2a46-377e-4a0d-8041-27dea9bc90b2" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Beta exam results 70-432, 70-448</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2008/10/08/BetaExamResults7043270448.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,d8f32bae-90b3-47a5-800b-a1f0dc26cf3c.aspx</id>
    <published>2008-10-08T10:55:23.5712198+02:00</published>
    <updated>2008-10-08T10:55:23.5712198+02:00</updated>
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <category term="Train_Cert" label="Train_Cert" scheme="http://resquel.com/ssb/CategoryView,category,TrainCert.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Just checked the <a href="https://www.register.prometric.com/CandidateHistory.asp" target="_blank">Prometric
site</a> and the status for my 70-432 (71-432) and 70-448 (71-448) changed from tested
to passed ;-).
</p>
        <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:36d2b8cf-2fd6-456e-aad4-f0f0fbc69b58" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati
tags: <a href="http://technorati.com/tags/MCTS" rel="tag">MCTS</a>, <a href="http://technorati.com/tags/70-432" rel="tag">70-432</a>, <a href="http://technorati.com/tags/70-448" rel="tag">70-448</a></div>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=d8f32bae-90b3-47a5-800b-a1f0dc26cf3c" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Fighting with the SSIS XML Source</title>
    <link rel="alternate" type="text/html" href="http://resquel.com/ssb/2008/08/08/FightingWithTheSSISXMLSource.aspx" />
    <id>http://resquel.com/ssb/PermaLink,guid,4fac4c46-b1e1-48a5-9434-4fa5e3eac48f.aspx</id>
    <published>2008-08-08T12:40:45.894599+02:00</published>
    <updated>2008-08-08T12:40:45.894599+02:00</updated>
    <category term="Intergation Services" label="Intergation Services" scheme="http://resquel.com/ssb/CategoryView,category,IntergationServices.aspx" />
    <category term="SQL Server" label="SQL Server" scheme="http://resquel.com/ssb/CategoryView,category,SQLServer.aspx" />
    <author>
      <name>Stan Segers</name>
    </author>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Yesterday evening I got into a fight with the SSIS XML Source Data Flow Source. It
actually was the first time I used this Data Flow Source. I had no expectations other
than, point to your XML-file and get the data. Wrong... I did point to an XML-file,
generate a schema and... no columns! I ended up with the error:
</p>
        <blockquote>
          <p>
Validation error. Data Flow Task: XML Source [<em>000</em>]: A component does not
have any inputs or outputs. 
</p>
        </blockquote>
        <p>
In cases like this, Google should be your friend... well I read a lot about SSIS in
general, some even about the XML Source but nothing to provide me with answers or
even help me out. It was after reading <a title="SSIS' 15 Faults" href="http://ayende.com/Blog/archive/2007/07/15/SSIS-15-Faults.aspx" target="_blank">a
post by Oren Eini</a> that I decided I was on the wrong trouble shooting track and
a good night sleep would be the best next step.
</p>
        <p>
This morning I started with clear vision and an open mind. No answers through Google,
nothing useful on <a href="https://connect.microsoft.com/SQLServer/Feedback" target="_blank">Connect</a>,
so I tried if I could reproduce my problem with an other document. The document I
created was of a very simple structure;
</p>
        <blockquote>&lt;people&gt;<br />
  &lt;person&gt;<br />
    &lt;firstname&gt;Jan&lt;/firstname&gt;<br />
    &lt;lastname&gt;Aerts&lt;/lastname&gt;<br />
  &lt;/person&gt;<br />
  &lt;person&gt;<br />
    &lt;firstname&gt;Anne&lt;/firstname&gt;<br />
    &lt;lastname&gt;Mulders&lt;/lastname&gt;<br />
  &lt;/person&gt;<br />
&lt;/people&gt; 
<p></p></blockquote>
        <p>
It worked! But now I had to find out why the document above worked, and the other
one didn't. Again I read about SSIS in general and a little something about the XML
Source. In particular (SSIS in general), I stumbled upon <a title="SSIS: The backlash" href="http://blogs.conchango.com/jamiethomson/archive/2007/07/27/SSIS_3A00_-The-backlash-continues.aspx" target="_blank">a
post by Jamie Thomson</a>, sounding familiar and one about the XML Source I wish I
came across earlier: <a href="http://blogs.msdn.com/mattm/archive/2007/12/11/using-xml-source.aspx" target="_blank">Using
XML Source</a> by Matt Masson. I could already agree with his opening comment, especially
the various degrees of success. While reading Matt's article I had this feeling my
XML document might actually be to simple... it occurred to me that the XML Source
was not just going to read XML, it was trying to represent the XML as one or more
tables.
</p>
        <p>
A very simple representation of my original document is;
</p>
        <blockquote>
          <table cellspacing="0" cellpadding="2" width="100%" border="0">
            <tbody>
              <tr>
                <td valign="top" width="50%">
  &lt;person id="1"&gt;<br />
    &lt;firstname&gt;Jan&lt;/firstname&gt;<br />
    &lt;lastname&gt;Aerts&lt;/lastname&gt;<br />
  &lt;/person&gt;<br /></td>
                <td valign="top" width="50%">
&lt;row column1="value"&gt;<br />
  &lt;column2&gt;value&lt;/column2&gt;<br />
  &lt;column3&gt;value&lt;/column3&gt;<br />
&lt;/row&gt;</td>
              </tr>
            </tbody>
          </table>
        </blockquote>
        <p>
The simplest representations Matt used, are:
</p>
        <blockquote>
          <table cellspacing="0" cellpadding="2" width="100%" border="0">
            <tbody>
              <tr>
                <td valign="top" width="50%">
&lt;rootgoo&gt;<br />
  &lt;goo&gt;<br />
    &lt;subgoo&gt;value&lt;/subgoo&gt;<br />
    &lt;moregoo&gt;1&lt;/moregoo&gt;<br />
  &lt;/goo&gt;<br />
  &lt;goo&gt;<br />
    &lt;subgoo&gt;value&lt;/subgoo&gt;<br />
    &lt;moregoo&gt;2&lt;/moregoo&gt;<br />
  &lt;/goo&gt;<br />
&lt;/rootgoo&gt;</td>
                <td valign="top" width="50%">
&lt;table&gt;<br />
  &lt;row&gt;<br />
    &lt;column1&gt;value&lt;/column1&gt;<br />
    &lt;column2&gt;value&lt;/column2&gt;<br />
  &lt;/row&gt;<br />
  &lt;row&gt;<br />
    &lt;column1&gt;value&lt;/column1&gt;<br />
    &lt;column2&gt;value&lt;/column2&gt;<br />
  &lt;/row&gt;<br />
&lt;/table&gt;</td>
              </tr>
            </tbody>
          </table>
          <p>
AND
</p>
          <table cellspacing="0" cellpadding="2" width="100%" border="0">
            <tbody>
              <tr>
                <td valign="top" width="50%">
&lt;root&gt;<br />
  &lt;row CustomerID="1" TerritoryID="1" AccountNumber="AW00000001" /&gt;<br />
  &lt;row CustomerID="2" TerritoryID="1" AccountNumber="AW00000002" /&gt;<br />
&lt;/root&gt;</td>
                <td valign="top" width="50%">
&lt;table&gt;<br />
  &lt;row column1="value" column2="value" column3="value" /&gt;<br />
  &lt;row column1="value" column2="value" column3="value" /&gt;<br />
&lt;/table&gt;</td>
              </tr>
            </tbody>
          </table>
        </blockquote>
        <p>
So my document could never be translated to a table... to get back to Oren's post:
If only SSIS had told me so with a clear error or even a dialog in the XML Source,
that would have saved me a couple of hours! 
</p>
        <p>
Or better, since XML Source tries to get data from the XML, it could do a best effort
as wrapping something that looks a single row into a table (and to take it one step
simpler, represent a single value as a table with just one row and one column.). If
you'd like to see some improvement here too, take a moment to vote on <a title="SSIS: Data Flow Source, XML Source better handle simple XML documents" href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=361057" target="_blank">FeedbackID
361057</a>.
</p>
        <p>
On a version note, it happens with SQL Server 2005 (SP2) and SQL Server 2008 (PreRelease).
</p>
        <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:309df610-67c7-4b98-839f-ec4420ea1f0c" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati
tags: <a href="http://technorati.com/tags/SQL%20Server%20Integration%20Services" rel="tag">SQL
Server Integration Services</a></div>
        <img width="0" height="0" src="http://resquel.com/ssb/aggbug.ashx?id=4fac4c46-b1e1-48a5-9434-4fa5e3eac48f" />
      </div>
    </content>
  </entry>
</feed>