SQL Server & BI blog by Andreas Wolter (Microsoft Certified Master): Database Engine - Reporting - Integration - Analysis Services

Andreas Wolter - SQL Server & BI blog (Database Engine, Reporting Services, Integration Services, Analysis Services)
Conferences 2013: Frankfurter Datenbanktage und einige “Oracle-Momente”

Normalerweise versuche ich ja, meine Konferenz-Teilnahmen vorab bekanntzugeben, um dem Leser auch eine Chance zu geben, diese eventuell einzuplanen.

Aufgrund akutem Zeitmangel, und auch dem Umstand gewidmet, das ich erst eine Woche vor der Konferenz spontan für einen ausgefallenen Sprecher eingesprungen bin, ist mir das diesmal nicht gelungen.

Ich hatte das Vergnügen, einen Vortrag über “Hochverfügbarkeitstechniken mit SQL Server 2012” zu halten. Ein kleines Interview mit meiner Person soll auch in den nächsten Tagen veröffentlich werden.

Ich möchte über die diesjährigen (ersten) Frankfurter Datenbanktage (der Termin für das nächste Jahr steht bereits fest: 26. - 28. März 2014) gerne noch im Nachhinein schreiben, da mir das Konzept mit gleichzeitigen Tracks & Sessions zu Oracle, DB2, MySQL, NoSQL und SQL Server sehr gefällt.

Es ist z.B. immer wieder interessant - aber auch bedauerlich, festzustellen, wie unbekannt Snapshot Isolation & RCSI in SQL Server eigentlich ist.
Das geht soweit, das in einer Session, in der es um die Fähigkeiten der verschiedenen Datenbanksysteme, während des Schreibens von Datensätzen, dennoch gleichzeitig einen konsistenten Zustand lesen zu können zu der Aussage kam, das nur Oracle dies beherrscht.
Das ist sehr schade.
Denn abgesehen davon, das diese Aussage so nicht richtig ist - SQL Server bietet 2 Varianten (eben Snapshot Isolation und Read Committed Snapshot Isolation), auf die das ebenso zutrifft; das Hintergrundwissen, das Microsoft den Entwicklern die Wahl zwischen vielen verschiedenen Isolationsstufen gibt, und warum dieses Konzept auch besser ist, als keine Wahl zu haben (oder zumindest so sehr auf nur eine festgelegt zu sein, das selbst Oracle-Admins meinen, es gäbe keine) scheint nicht so weit verbreitet zu sein, wie man es sich erhoffen würde.

Eine andere Session, die ich nur lesenderweise mir ansah, hat mich als Security Spezialist für SQL Server schon fast geschockt: Es ist zwar kein Geheimnis (auch wenn es interessanterweise gerade im Bankenbereich gern ignoriert wird), wie umfangreich die Anzahl der Sicherheitslücken in ORACLE ist (Beim "NIST" kann man sich darüber informieren: nvd.nist.gov), aber in welchem Ausmaß man selbst ohne spezieller Betrachtung derer eine sogenanntes Sicherheits-“Härtung” durchführen muss, um einigermaßen sicher vor den gröbsten Einfallstoren zu sein, hat mich als seit SQL Server 2005 “secure by default” gewohnter doch sehr überrascht. - Möglichst “sanft" (Session-Untertitel "Sanftes Härten"), damit danach auch noch alles funktioniert - und wir wollen die Angreifer ja auch nicht völlig vergraulen, oder? :) (Nachtrag: natürlich ist es nachvollziehbar, das man nicht einfach so alles "dicht" macht, und danach auch die validen Anwendungen nicht mehr funtionieren. Die Essenz ist: es muss ein Mittelweg gefunden werden, welcher die Angreifbarkeit und Verletzbarkeit zumindest mindert. Und das ist natürlich schon viel Wert!)
Welche meiner Daten so "geschützt" in Oracle-DBs liegen, wäre vielleicht gut zu wissen... ganz ohne Häme, denn der einzelne Kunde kann dafür meistens gar Nichts. - Nur wenn er informiert ist und gar nicht handelt (Und nicht einmal mildernd eingreift).

Um es aber auch klar zu sagen: auch einen SQL Server kann man angreifen, wenn Applikationen oder andere Verbindungen mit zu viel Rechten laufen, Service Accounts geshared werden, etc.. Deswegen hier noch einmal die beiden wichtigsten Sicherheitsprinzipien: "Separation of duties/roles" und "Principle of least privilege". Also Aufgaben/Rollen (Dienstkonten!) trennen und immer mit den geringstmöglichen Rechten arbeiten. Und oben drauf ein Auditing, damit man mitbekommt, wenn man einen Weg übersehen hat.

Und nicht zuletzt wegen der Möglichkeit solche Missverständnisse oder Vergleiche einmal live zu erfahren, oder auch einfach ganz andere Möglichkeiten, die es bei anderen DBMS ja auch gibt, kennenzulernen, empfinde ich die Frankfurter Datenbanktage als Bereicherung in der Konferenz-Landschaft.

Tatsächlich versucht die PASS Deutschland e.V. eine kleine Variante solcher Mixtur auch für den geplanten SQLSaturday #230 in Rheinland, auf welchem ich sicherlich auch anzutreffen sein werde, mit einzubringen. Ich bin gespannt, was daraus wird, und wie es aufgenommen wird.

 

vielleicht sieht man sich auf der nächsten Konferenz,

 

Andreas

Tracing Analysis Services with Extended Events – Yes it works and this is how

or: “Hasta la vista, Profiler”..

One of the features new in Analysis Services 2012 is the support of the SQL Server Extended Events Framework.

While there is no GUI support for that, yet, it is however possible to set up a XEvent session via DDL commands - just like it was in the “old days” with SQL Server 2008/ 2008 R2, until 2012 brought the GUI.

Since I have been asked a lot at my sessions on Extended Events on how it is done in Analysis Services, and the Books Online sample code is not really working (“Use SQL Server Extended Events (XEvents) to Monitor Analysis Services
http://msdn.microsoft.com/en-us/library/gg492139.aspx”), I will show a quick example here.

The following code creates a session to collect the deadlocks events from the Analysis Services Instance:

Eines der in Analysis Services 2012 neuen Features ist die Unterstützung des SQL Server Extended Events Frameworks.

Obwohl dafür noch keine grafische Unterstützung da ist, ist es jedoch möglich eine XEvent Session über DDL Kommandos aufzusetzen - genau wie in den alten Zeiten” mit SQL Server 2008/ 2008 R2, bis 2012 die GUI brachte.

Da ich im Zuge meiner Sessions zu Extended Events häufig gefragt wurde, wie das bei Analysis Services funktioniert, und das Books Online Beispiel nicht wirklich funktioniert (“Use SQL Server Extended Events (XEvents) to Monitor Analysis Services
http://msdn.microsoft.com/en-us/library/gg492139.aspx”), zeige ich hier ein kurzes Beispiel.

Der folgende Code erzeugt eine Session um Deadlock Events von einer Analysis Services Instanz mitzuschneiden:

<Create xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ddl2="http://schemas.microsoft.com/analysisservices/2003/engine/2" xmlns:ddl2_2="http://schemas.microsoft.com/analysisservices/2003/engine/2/2" xmlns:ddl100_100="http://schemas.microsoft.com/analysisservices/2008/engine/100/100" xmlns:ddl200_200="http://schemas.microsoft.com/analysisservices/2010/engine/200/200" xmlns:ddl300_300="http://schemas.microsoft.com/analysisservices/2011/engine/300/300">
    <ObjectDefinition>
        <Trace>
            <ID>Sarpedon AS Trace Demo</ID>
            <Name>Sarpedon AS Trace Demo</Name>
            <ddl300_300:XEvent>
                <event_session name="SQL_AS_XE" dispatchLatency="10" maxEventSize="4" maxMemory="4" memoryPartitionMode="none">
                    <event package="AS" name="Deadlock" />
                    <target package="Package0" name="event_file">
                        <parameter name="filename" value="D:\SQLData\SarpedonASDeadlockTrace.xel" />
                    </target>
                </event_session>
            </ddl300_300:XEvent>
        </Trace>
    </ObjectDefinition>
</Create>

As one can see, the definition like session configuration and targets, is quite similar to SQL Server, since it is in fact based on the same architecture.
The package containing the events is AS, whereas targets come from our well known Package0. The one familiar with XEvents will know, what this implicates - more maybe in a later post.

Via the internal system view $system.discover_traces, we can see the active traces on the instance: the “FlightRecorder” which is still using the old-style Tracing technology (I wonder when Microsoft will add a new one just like system_health in SQL Server) and my Sample session. You will also note, that the XEvent session’s Trace File name is not visible here.

Wie man sehen kann, ist die Definition wie Session-Konfiguration und Targets recht ähnlich zu SQL Server, da es tatsächlich auf der selben Architektur basiert.
Das Package welches die Events enthält, ist AS, wohingegen die Targets aus dem bereits bekannten Package0 stammen. Wer bereits mit XEvents vertraut ist, wird wissen, was das impliziert - mehr vielleicht in einem späteren Post.

Über die interne Systemsicht $system.discover_traces können wir die aktiven Traces auf der Instanz sehen: der “FlightRecorder”, der noch die alte Tracing Technik verwendet (Ich frage mich, wann Microsoft eine Neue, wie die system_health in SQL Server hinzufügen wird), und meine Beispiel-Sitzung. Man sieht auch, das der Trace Dateiname der XEvent-Session hier nicht sichtbar ist.

Trace Sessions

To access the collected data one can easily stop and delete the session by name as follows:

Um auf die gesammelten Daten zuzugreifen, kann man die Trace session wie folgt bequem über den Namen beenden und löschen:

<Delete xmlns="http://schemas.microsoft.com/analysisservices/2003/engine" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<Object>
<TraceID>Sarpedon AS Trace Demo</TraceID>
</Object>
</Delete>

The collected data can be viewed, aggregated and filtered as normal with the Extended Events Viewer in Management Studio.
Here a sample with query runtimes:

Die gesammelten Daten lassen sich dann wie gewohnt über den Extended Events Viewer in Management Studio ansehen, aggregieren und filtern.
Hier ein Beispiel mit Query-Laufzeiten:

XEvent Viewer

In the detail pane on the bottom you can notice, that I turned on causality tracking here. Hence the activity ID /GUID correlate activity.

Im Detailbereich kann man sehen, das ich hier auch Kausalitätstracking eingeschaltet habe. Daher die activity ID/GUI um Aktivitäten zu korrelieren.

So as you see, for a fact, the Analysis Services engine has been extended to be using the Extended Events architecture for better performing and more flexible Tracing.
I do expect some more GUI-support for Managing XEvents in Analysis Services in the next major release.

Have fun, playing around with the sample. :-)

From now on there is no excuse any more, to burden an Analysis Server that is already on its knees with Profiler...

Wie man sehen kann, sind die Analysis Services tatsächlich erweitert worden um die Extended Events Architektur für performanteres und flexibleres Tracing zu verwenden.
Mit dem nächsten Major-Release des SQL Server erwarte ich mehr GUI-Unterstützung  für die Verwaltung von XEvents in Analysis Services.

Viel Spaß beim Herumspielen mit dem Beispiel. :-)

Ab jetzt gibt es keine Entschuldigung mehr, einen Analysis Server, der bereits auf den Knien ist, weiter mit dem Profiler zu belasten...

“Hasta la vista, Profiler” Winking smile

Hopefully by MCM buddy and friend Reeves Smith will soon write his promised post on Tracing Analysis Services, maybe with a Performance Comparison.
”So, now you have to get going, Reeves!”  Open-mouthed smile

Hoffentlich wird mein MCM Kollege und Freund seinen versprochenen Post über XEvent Tracing Analsis Services bald einlösen – vielleicht mit einem Performance-Vergleich.
”So, nun musst Du aber loslegen, Reeves!”  Open-mouthed smile

Meanwhile I’d like to refer you to this article from another fellow MCM, Jonathan Kehayas, where you can see the enormous difference in terms of negative performance-impact of tracing via Profiler and SQL Trace vs XEvents:

Bis dahin verweise ich gerne auf diesen Artikel eines andern MCM Kollegen, Jonathan Kehayas, wo man den gewaltigen Unterschied des negativen Performance-Einflusses von Tracing mittels profiler aund SQL Trace gegenüber Extended Events sieht:

http://www.sqlperformance.com/2012/10/sql-trace/observer-overhead-trace-extended-events

 

Andreas

Hinweis: es wird noch im 1. HJ 2013 einen zweiten Termin für die Master-Class Seminare zu Extended Events geben: http://www.sarpedonqualitylab.com/SQL_Master-Classes.htm

SQL Server Master-Class Seminare – Für Alle, die es genau wissen wollen – Start im Mai mit Extended Events

Ich werde häufig darauf angesprochen, ob ich nicht mal ein Buch schreiben möchte, um mein Wissen so weiterzugeben, oder Deep-Dive Seminare anbiete, wie es einige andere Kollegen in den USA tun.

Um ein Buch zu schreiben, habe ich leider nicht die Zeit. Ein komplettes Buch würde mich zu sehr von der Praxis abhalten - und Praxis ist das A und O - zumal es ständig neue Dinge zu lernen gibt.

In Seminaren und Vorträgen hingegen, hat man einen kurzen Zyklus, und sieht den Erfolg direkt. Abgesehen davon, das ich mein Wissen gerne weitergebe, macht die Interaktion einfach Spaß.

Ich habe mir überlegt, und mich auch unter Kollegen umgehört, was an anderen Angeboten, die ich selber oder andere kennengelernt haben, störte, und kam zu folgenden Kern-Punkten:

  1. Reine Präsentation mit zwar Deep-Dive Inhalten, aber kaum eine Chance, diese mit Übungen direkt vor Ort zu festigen (sehr typisch für die USA, ob PreCon-“Workshops” oder Seminare, das ist eher immer Vortragsstil und Demos, aber keine echten “Hands-On”) – und nach der Schulungswoche hat man oft keine Zeit mehr dafür.
  2. Viele Themenkomplexe innerhalb einer oder mehrer Wochen, die man gar nicht alle mehr benötigt, aber Bestandteil der 5 Tage sind. – Und diese 5 Tage sind dann auch komplett blockiert.
  3. Weite und damit teure Anreise.

Und nun ist es soweit: ab diesem Sommer biete ich eine eigene Deep-Dive Trainingsreihe, “SQL Server Master-Classes” an.

SQL_Server_Master-Classes

Und was ist hier anders?:

  1. Es sind immer Übungen und auch Zeit für diese eingeplant, so dass man das gerade erlernte gleich ausprobieren kann. In den SQL Server Master-Classes, die “Workshop” in der Bezeichnung tragen, beträgt der Praxisanteil ca. 40%.
  2. Server Master-Classes sind jeweils 1 - max. 3-tägige Veranstaltungen, die jeweils einen Themenkomplex abdecken.
    Z.B. 1 Tag “Concurrency” mit allem, was zum Thema Transaktions-Isolation, Locking & Blocking gehört, oder 2 Tage “Indexe, Statistiken und Partitionierung”, denn das Thema ist ein einem Tag nicht zu schaffen. Beides lässt sich aber einzeln buchen, obwohl es insgesamt natürlich zum Thema “Performance” gehört.
  3. “Learn from a Master” - Zum einen sind dies die ersten regulär angebotenen offenen Seminare mit einem Certified Master (MCM + MCT) als Instruktor in und aus Deutschlandimage
    - zum anderen kann ich für die in Frankfurt laufenden Seminare einen absoluten Knüllerpreis für Bahnfahrer anbieten: 99,- Euro für Deutschlandweite An- und Abreise. (Details dazu auf der webseite: www.sarpedonqualitylab.com/SQL_Master-Classes.htm)
  4. Nur um Sicherzugehen: der Vergleich mit MOC-Kursen wird gar nicht erst versucht. Hier geht es nicht nur um Best Practices, sondern es soll erlernt werden, was dahinter steckt, um den BESTEN Weg zu ermitteln, und nicht die “allgemeine Best Practice”.
  5. Natürlich wird sich auch ganztägig um das leibliche Wohl gesorgt. Die Seminare finden in einer hochwertigen Location statt, und ein Mittagsmenü sowie Pausensnacks (Kaffee, Tee, Kuchen uä.) und “Getränke-Flat” gehören dazu.

Und nun zu den Inhalten:

Folgende Themenkomplexe sind derzeit vorbereitet:

  • Workshop Tracing mit Extended Events in SQL Server (1 Tag)
  • Workshop Fortgeschrittene Techniken für Tracing mit mit Extended Events in SQL Server (1 Tag)
  • Concurrency - Transaktionen, Isolation Level und Sperren (1 Tag)
  • Indexe, Statistiken und Partitionierung (2 Tage)
  • Optimierung von Prozeduren und Funktionen (1 Tag)
  • Performance und Analysetechniken & -Tools + Workshop (2 Tage)
  • Baselining & Benchmarking (1 Tag)
  • Sicherheitsworkshops (Essentials, Vertiefung für Entwickler, Vertiefung für Administratoren, je 1 Tag)
  • Wiederherstellungsstrategien und Techniken (1 Tag)
  • Workshop Hochverfügbarkeit (2 Tage)
  • Beyond Relational mit SQL Server - Filestream, FileTable, FullTextSearch, Geospatial (1 Tag)
  • Workshop Replikation (1 Tag)

Und los geht es mit XEvents:

  • Workshop Tracing mit Extended Events in SQL Server (1 Tag)
    • Frankfurt am Main, 17.5.2013
  • Workshop Fortgeschrittene Techniken für Tracing mit mit Extended Events in SQL Server (1 Tag)
    • Frankfurt am Main, 18.5.2013

Bis zum 29.3. läuft noch der Super-Early-Bird, und bis zum 22.4. der Early-Bird!
Mitglieder der PASS Deutschland e.V. erhalten einen Rabatt von 10%

Hier geht es zur aktuellen Liste und Anmeldung: www.sarpedonqualitylab.com/SQL_Master-Classes.htm

happy learning,

Andreas

------------------------------------------------------------------------

Andreas Wolter | Microsoft Certified Master SQL Server

MCT, MCITPDD, MCITPBID, MCITPDA, MCDBA, MCSA, MCTS
Sr Technical Consultant & Architect Datenbanken & BI

Sarpedon Quality Lab

Locking & READONLY Filegroups vs READONLY Databases // Sperren & READONLY Dateigruppen vs READONLY Datenbanken
The Topic Locking and Read-Only for filegroups and databases is one of the ongoing myths around SQL Server in forums – and at least half of the information unfortunately wrong.
Since I recently fell into the trap myself, I want to write down, how it really is.

To have a definite picture, I made 3 test series under 3 different isolation levels:
  • Read Commited (the default)
  • Read Uncommitted (equal to the often misunderstood “NOLOCK”)
  • Repeatable Read

     

    The Setup:


    Tested under:
    Microsoft SQL Server 2012 - 11.0.2376
    A Test using SQL Server 2008 R2 produced identical results

    The base is a simple table, which has a Clustered Index. Altogether it consists of 36 pages
    (In case you wonder about the name – I had also tested with a single-Page table)

  • Das Thema Sperren im Zusammenhang mit Readonly Filegroups und Datenbanken geistert immer wieder durch die Foren - und mindestens zur Hälfte leider mit Falschinformationen angereichert. Da ich kürzlich selber in die Falle tappte, möchte ich hiermit schwarz auf weiß festhalten, wie es sich wirklich verhält.

    Um ein eindeutiges Bild zu erhalten, habe ich Testreihen unter 3 verschiedenen Isolation Levels durchgeführt:

  • Read Commited (also dem Standard)
  • Read Uncommitted (gleichbedeuted mit dem ebenfalls gerne missinterpretierten “NOLOCK”)
  • Repeatable Read

    Das Setup:

    Getestet unter:
    Microsoft SQL Server 2012 - 11.0.2376
    Ein Test unter SQL Server 2008 R2 ergab identische Ergebnisse

    Basis ist eine simple Tabelle, welche mit einem Clustered Index versehen ist. Insgesamt besteht sie aus 36 Pages.
    (Falls ihr Euch über den Namen wundert: ich hatte auch Test mit einer single-Page Tabelle gemacht)

  • Databases

    Read-Only Filegroup

    USE
    LockingDemo_RW
    go
    exec sp_help 'BigTable'

    Data_located_on_filegroup
    PRIMARY

    index_name    index_description
    PK__BigTable__3213E83FFF01B718    clustered, unique, primary key located on PRIMARY

    USE LockingDemo_RO

    Data_located_on_filegroup
    PRIMARY

    index_name    index_description
    PK__BigTable__3213E83FFF01B718    clustered, unique, primary key located on PRIMARY

    Identical structure so far except the database LockingDemo_RW_FG_RO – here the Table resides on filegroup FG_RO Also ein identischer Aufbau, bis auf die Datenbank LockingDemo_RW_FG_RO – hier ist die Tabelle auf der Filegroup FG_RO

    USE LockingDemo_RW_FG_RO

    Data_located_on_filegroup
    FG_RO

    index_name    index_description
    PK__BigTable__3213E83FC5587D01    clustered, unique, primary key located on FG_RO

    The first/upper query shows the total amount of data, the lower is used as the test query: Die die erste/obere Abfrage zeigt die Gesamtdatenmenge, die untere wird als Testabfrage verwendet:

    1)
    SELECT * FROM BigTable

    (1000 row(s) affected)

    Table 'BigTable'. Scan count 1, logical reads 36, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

    2) – The Testquery / die Testabfrage

    SELECT
    * FROM BigTable

        WHERE id BETWEEN 100 AND 200

    (101 row(s) affected)

    Table 'BigTable'. Scan count 1, logical reads 6, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

    This is what the test looked like (abbreviated): So sah der Testlauf aus (abgekürzt):

    --====================

    --  1

    --====================

     

    SET TRANSACTION ISOLATION LEVEL READ COMMITTED

     

     

    USE LockingDemo_RW

    go

     

    BEGIN TRAN

     

    SELECT * FROM BigTable

        WHERE id BETWEEN 100 AND 200

     

    COMMIT TRAN

     

     

    USE LockingDemo_RO

    go

     

    BEGIN TRAN

     

    SELECT * FROM BigTable

        WHERE id BETWEEN 100 AND 200

     

    COMMIT TRAN

     

     

    USE LockingDemo_RW_FG_RO

    go

     

    BEGIN TRAN

     

    SELECT * FROM BigTable

        WHERE id BETWEEN 100 AND 200

     

    COMMIT TRAN

     

    USE master

     

    --====================

    -- 2

    --====================

     

    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

     

    ...

     

    --====================

    -- 3

    --====================

     

    SET TRANSACTION ISOLATION LEVEL REPEATABLE READ

     

    ...

    Parallel to that, an extended events session was running (Lock-escalation isn’t happening in this scenario) Parallel dazu lief eine Extended Events session
    (Lock-Escalation tritt in diesem Szenario nicht auf)

    CREATE EVENT SESSION [Locking] ON SERVER

    ADD EVENT sqlserver.lock_acquired(

        ACTION(package0.event_sequence,sqlserver.database_id,sqlserver.is_system,sqlserver.session_id)

        WHERE ([sqlserver].[database_id]>=(23) AND [sqlserver].[database_id]<=(25)))

    ADD TARGET package0.event_file(SET filename=N'D:\SQLData\SQLData1\Locking.xel')

    WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=1 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)

    GO 

    Results

    (Locks with granularity / resource_type = DATABASE left out)

    1. Read Committed

    Resultate

    (Sperren mit Granularität / resource_type = DATABASE ausgelassen)

    1. Read Committed

    Locks under Read Committed

    2. Read Uncommitted

    (for obvious reason I left out the sub-totals :-)

    2. Read Uncommitted

    (aus offensichtlichem Grund habe ich die Zwischensummen weggelassen :-)

    Locks under Read Uncommitted

    3. Repeatable Read

    3. Repeatable Read

    Locks under Repeatable Read

    A note about Statistics und eXclusive Locks on ReadOnly-Databases:

    Yes, one can indeed watch X-Locks on Read-Only databases. And this happens when auto-created stats jump in.
    This works only starting with SQL Server 2012. The statistics themselves are stored in Tempdb.
    In order to create those, SQL Server generates SCH_S and METADATA locks on several system objects (here: sysallocunits, sysschobjs, sysobjvalues, syssingleobjrefs, sysobjkeycrypts):

    Eine Bemerkung zu Statistiken und eXklusive-Sperren auf schreibgeschützten Datenbanken:

    Ja, tatsächlich kann man auch auf Read-Only Datenbanken hin und wieder X-Locks beobachten. Und zwar wenn auto-created Statistics einspringen.
    Das funktioniert erst seit SQL Server 2012. Dabei werden die Statistiken selber in der Tempdb hinterlegt.
    Um sie zu erzeugen, generiert SQL Server SCH_S und METADATA Locks auf diverse Systemobjekte (hier: sysallocunits, sysschobjs, sysobjvalues, syssingleobjrefs, sysobjkeycrypts):

    image

    This is of course not the most common scenario, but it does happen (especially in AlwaysOn scenarios with read-only secondaries involved) and belongs to a complete picture.

    -

    Besides that one can see on first sight, that there is no diffference in the Locking behaviour beetween the table on a ReadWrite Filegroup (here Primary) and the table on the ReadOnly filegroup.

    Only if the whole database is ReadOnly, SQL Server  saves himself the Page- and Key- locks.
    Even there an Intent shared Lock is placed on the table.

    Conclusion:

    Putting Tables onto a ReadOnly-Filegroup does not save Locks.
    But it often does make a lot of sense, to break up databases in this manner.
    Just thinking of: less backup, faster restore, NTFS-compression etc.
    Das ist sicherlich nicht das am meisten übliche Szenario, aber es tritt auf (insbesondere in AlwaysOn Szenarien mit read-only Secondaries) und gehört zu einem vollständigen Bild.

    -

    Abgesehen davon erkennt man auf den ersten Blick, das kein Unterschied im Sperrverhalten zwischen der Tabelle auf einer ReadWrite Filegroup (hier Primary) und der Tabelle auf der ReadOnly Filegroup besteht.

    Nur wenn die gesamte Datenbank ReadOnly ist, spart sich SQL Server die Page- und Key- Locks. Selbst dort jedoch wird ein Intent-Share-Lock auf die Tabelle gesetzt.

    Fazit:

    Tabellen auf eine ReadOnly-Dateigruppe zu verlegen spart keine Sperren.
    Aber es macht natürlich trotzdem oft sehr viel Sinn, Datenbanken so aufzuteilen.
    Ich denke da nur an: Weniger Backup, schnellere Wiederherstellung, NTFS-Komprimmierung  etc.

    Andreas

    Sarpedon Quality Lab

    Upcoming Conferences 2012: PASS SQLSaturday in Munich, SQLCon in Mainz, PASS SQLRally in Copenhagen, PASS Summit in Seattle, PASS Camp in Darmstadt

    ..ough
    After I already launched the SQL Server 2012 together with Microsoft at Cologne this February, this year’s second half I will be speaker at 5 Conferences almost in a row:

     

    SQLSaturday #170 - Munich 2012

     

    Basta! 2012 Speaker

     

    SQL PASS Rally Nordic

     

    • From October 22nd – 25th I will hold several sessions on:
      AlwaysOn and ReadOnly Routing”, “Data Corruption Survival with CHECKDB”,  “Security” and “Tracing with Extended Events
      in the track
      SQL Server 2012 Toolbelt for DBA’s and Developer
      in Seeheim, close to Darmstadt, Germany at the PASS Camp

     

    SQL PASS Summit 2012

     

    what a year..!

    I hope to see you around at some of those places.



    Andreas

    “Brought to you this summer”: Microsoft Certified Master SQL Server

    (Deutsche Übersetzung unten/German translation below)

    as some of you already may have heard: this June I passed my Lab Exam for the Microsoft Certified Master SQL Server 2008.
    - almost exactly 3 months after my first attempt. In fact the Exam has already taken place in the middle of May. - Unfortunately this time I had to wait more than 30 days until I received my result, and it took another couple of weeks, until my name made it onto the official MCM-List: http://www.microsoft.com/learning/en/us/certification/master.aspx#meet

    The MCM is the highest technical certification that Microsoft offers (http://www.microsoft.com/learning/en/us/certification/master-sql.aspx), and unlike the MCITP or even MVP the MCM is only awarded for a so called knowledge exam plus a practical lab exam of approximately 5 1/2 hours practical problem solving on a SQL Server box.
    In fact, as of September 2012, I am the only Microsoft Master for SQL Server in Germany outside of Microsoft and affiliates. :-)

    At TechNet’s Master Blog you can now also find a short introduction of myself (Thank you, Bob Taylor): http://blogs.technet.com/b/themasterblog/archive/2012/08/20/introducing-our-latest-sql-server-2008-microsoft-certified-master-andreas-wolter.aspx

    Thanks to all the people that believed in me, and to those that made me pursue it even more determined :-)
    Among them: Paul Randall and Kimberley Tripp from SQLSkills - my number one teachers, in general terms, since several years, Jonathan Kehayias and Bob Beauchemin who added valuable knowledge in SQL OS and Developing, Robert Davis, who graded my first Lab within hours, and last but not least: Ralf Dietrich, my long term sparring partner for SQL Server and uncertified Master in Germany ;-)

    Also I have to apologize to all my customers for often letting them wait long because I made my studies number one priority. It will be made up by even better and more effective consulting skills :-)

    MCM 2008

    Andreas Wolter

    CEO | Sr Technical Consultant & Architect Databases & BI

    SARPEDON Quality Lab

    Certification-Status as of Oct. 2012 (SQL Server Version in brackets):

    MCM (2008), MCT (2005 – 2012), MCSA (2008), MCITPDD (2005 - 2008), MCITPBID (2008), MCITPDA (2005-2008), MCDBA (2000), MCSA (Win 2003), MCTS (2005 – 2008)

     

    (German translation):

    wie viele sicher schon gehört haben, habe ich diesen Juni das Lab Exam für den Microsoft Certified Master SQL Server 2008 bestanden.
    - fast genau 3 Monate nach meinem ersten Versuch. Tatsächlich war das Exam schon Mitte May. – Leider musste ich diesmal mehr als 30 Tage auf meine Ergebnisse warten, und es dauerte weitere Wochen, bis mein Name es auf die offizielle MCM-Liste machte: http://www.microsoft.com/learning/en/us/certification/master.aspx#meet

    Der MCM ist die höchste technische Zertifizierung, die Microsoft anbietet (http://www.microsoft.com/learning/en/us/certification/master-sql.aspx), und anders als der MCITP oder sogar MVP wird der MCM nur nach einem sogenannten knowledge exam plus einem praktischen lab exam von rund 5 1/2 Stunden praktischem Problemlösen an einer SQL Server box verliehen.
    Bislang (Stand Oktober 2012) bin ich sogar der einzige von Microsoft unabhängige Master für SQL Server in Deutschland. :-)

    Auf dem Master Blog von TechNet finden sie eine kurze Vorstellung über mich (Thank you, Bob Taylor): http://blogs.technet.com/b/themasterblog/archive/2012/08/20/introducing-our-latest-sql-server-2008-microsoft-certified-master-andreas-wolter.aspx

    Mein Dank geht an alle, die an mich glaubten, und die, welche mich das Ziel noch entschlossener verfolgen ließen :-)
    Unter ihnen: Paul Randall und Kimberley Tripp von SQLSkills – meine, im weitesten Sinne, Nummer eins Tutoren seit einigen Jahren, Jonathan Kehayias und Bob Beauchemin, die wertvolles Wissen in SQL OS und Developing beisteuerten, Robert Davis, der mein erstes Lab innerhalb von wenigen Stunden benotete, und last but not least: Ralf Dietrich, mein langjähriger Sparring Partner für SQL Server und uncertified Master in Deutschland ;-)

    Bei meinen Kunden muss ich mich entschuldigen, dass ich sie oft lange warten ließ, da meine Studien oberste Priorität bei mir wurden. Das wird durch noch bessere und effizientere Consulting-Skills wettgemacht werden :-)

    MCM 2008

    Andreas Wolter

    Geschäftsführer | Sr Technical Consultant & Architect Datenbanken & BI

    SARPEDON Quality Lab

    Zertifizierungs-Status Stand Okt. 2012 (SQL Server Version in Klammern):

    MCM (2008), MCT (2005 – 2012), MCSA (2008), MCITPDD (2005 - 2008), MCITPBID (2008), MCITPDA (2005-2008), MCDBA (2000), MCSA (Win 2003), MCTS (2005 – 2008)

    Sessions auf der SQLCon 2011

    Auch dieses Jahr bin ich wieder mit bis dato zwei Sessions auf der SQLCon 2011 – 26. – 29. September in Mainz vertreten.

    Update (09/2011): Den Vortrag “Reporting Services in SQL Server Denali” habe ich zugunsten eines mir noch mehr am Herzen liegenden Themas gestrichen. (Außerdem werden die Reporting Services selber kaum viele Neuereungen in Denali erfahren)
    Dafür halte ich eine Session zu den Sicherheits-Features & Techniken von SQL Server für Entwickler:

    “Schutz gegen SQL Injection sollte mittlerweile zum Repertoire jedes Entwicklers gehören. Jedoch gibt es noch andere Wege, an sensible Daten zu gelangen oder sie zu manipulieren. In dieser demointensiven Session (Achtung: Code, Code) werden wir uns vor allem anderen Techniken widmen, die man im Repertoire haben sollte, die Sicherheit seiner Daten zu stärken. Dazu gehören Basics wie Schema-Design für Security, Besitzerketten und ihre Fallstricke, Codesignierung und Verschlüsselung für die kritischsten Daten.“

    ”Wer Berichte mit Reporting Services erstellt, wird feststellen, dass ganz schnell nach weiteren verlangt wird. Und früher oder später kommt der Ruf nach einem einheitlichen Aussehen. Die Unterstützung dafür out of the box ist eher schwach. Dennoch kann man mit geschickter Kombination der zur Verfügung stehenden Möglichkeiten eine starke Effizienz-Steigerung beim Erstellen neuer Berichte erreichen.“

     

    Ich würde mich freuen, den einen oder anderen persönlich, “offline”, begrüßen zu können.

    Andreas Wolter

    Sarpedon Quality Lab

    High-Level Training

    sqlcon2011_extern_viewport

    Standardizing and Centralizing Report Design (or: creating style sheets for reports) Part 3: The Style-Template

    In the first part we learned how to integrate a Layout-Template into BIDS. The second technique in this series we are looking at will be using the “Style-Template”.

    What is a Style-Template?:

    Style-Templates are a set of definitions such as font size, font type, font color, background color, border styles, etc., which is being used from within the “Add New Report” wizard inside Business Intelligence Development Studio.

    Report Layout-Templates are shown in the Project-Dialogue “Add“ – “New Item“ .

    image

    This is where you usually chose among those beautiful styles, that Microsoft provides you with (Slate, Forest, Corporate, Ocean, Bold, Generic) Open-mouthed smile.

    image

    But: you can include your own style definition!

    And this is how we can create a Style-Template:

    1) Open the file StyleTemplates.xml from the following location (watch for your locale specific folder at the end) using your favorite XML Editor (notepad is sufficient):

    for Reporting Services 2005

      •%ProgramFiles%\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\Business Intelligence Wizards\Reports\Styles\en

    for Reporting Services 2008 x64

      •%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\Business Intelligence Wizards\Reports\Styles\en

    for 32-bit Reporting Services 2008

    • C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\Business Intelligence Wizards\Reports\Styles\en

    2) I strongly advice you create a backup of StyleTemplates.xml before you edit it:

    3) Look for a complete “StyleTemplate”-node like “<StyleTemplate Name="Slate"> … </StyleTemplate>” and copy it to the end, just before the Generic-Style (<StyleTemplate Name="Generic">)

    4) Rename the copied definition

    5) Now you can start changing colors, border styles, fonts etc.

    You will find out, that not everything will be accepted. There is no documentation and so far this is what I can give you as a set of rules I found out the hard way – hope it helps saving you time:

    Rules of engagement for producing a Style-Template:

    • Backup StyleTemplates.xml before editing it!
    • Watch out for whitespaces and line breaks. Otherwise you will get Error messages such as “Red is not a valid color”.
    • Not all Attributes are supported and give you an error when running the wizard.
      • I.e. <TopBorder> etc.
    • Some fail silently like “<BorderWidth>”
    • Color values have no spaces between words
      • “Dark Olive Green” is coded “DarkOliveGreen”
    • Font names can include spaces
      • <FontFamily>Times New Roman</FontFamily>
    • TextAlign does not work in "Table Header" – sometimes align in header rows is out of order for no reason
    • default font for table does not work here either

    Sample Style-Template code:

    <StyleTemplate Name="Pizza_Time">
        <Label>Pizza_Time</Label>
        <Styles>
            <Style Name="Title">
                <FontFamily>Tahoma</FontFamily>
                <FontSize>20pt</FontSize>
                <Color>Red</Color>
                <TextDecoration>Underline</TextDecoration>
            </Style>
            <Style Name="Page Group Level 1">
                <FontFamily>Tahoma</FontFamily>
                <FontSize>14pt</FontSize>
            </Style>
            <Style Name="Page Group Level 2">
                <FontFamily>Tahoma</FontFamily>
                <FontSize>12pt</FontSize>
            </Style>
            <Style Name="Page Group Level 3+">
                <FontFamily>Tahoma</FontFamily>
                <FontSize>10pt</FontSize>
            </Style>
            <Style Name="Table"></Style>
            <Style Name="Matrix"></Style>
            <Style Name="Table Header">
                <BackgroundColor>Tomato</BackgroundColor>
                <FontFamily>Tahoma</FontFamily>
                <FontSize>11pt</FontSize>
                <FontWeight>Bold</FontWeight>
                <Color>White</Color>
                <BorderStyle>
                    <Default>Solid</Default>
                </BorderStyle>
                <BorderColor>
                    <Default>DimGray</Default>
                </BorderColor>
            </Style>
            <Style Name="Group Level 1">
                <FontFamily>Tahoma</FontFamily>
                <FontSize>11pt</FontSize>
                <FontWeight>Bold</FontWeight>
                <Color>DarkOliveGreen</Color>
                <BackgroundColor>Wheat</BackgroundColor>
                <BorderStyle>
                    <Default>Solid</Default>
                </BorderStyle>
                <BorderColor>
                    <Default>DimGray</Default>
                </BorderColor>
            </Style>
            <Style Name="Group Level 1 Textbox">
                <FontFamily>Tahoma</FontFamily>
                <FontSize>11pt</FontSize>
                <FontWeight>Bold</FontWeight>
                <Color>DarkOliveGreen</Color>
                <BackgroundColor>Wheat</BackgroundColor>
                <BorderStyle>
                    <Default>Solid</Default>
                </BorderStyle>
                <BorderColor>
                    <Default>DimGray</Default>
                </BorderColor>
            </Style>
            <Style Name="Group Level 2">
                <FontFamily>Tahoma</FontFamily>
                <FontSize>10pt</FontSize>
                <FontWeight>Bold</FontWeight>
                <Color>DarkOliveGreen</Color>
                <BackgroundColor>LightSalmon</BackgroundColor>
                <BorderStyle>
                    <Default>Solid</Default>
                </BorderStyle>
                <BorderColor>
                    <Default>DimGray</Default>
                </BorderColor>
            </Style>
            <Style Name="Group Level 2 Textbox">
                <FontFamily>Tahoma</FontFamily>
                <FontSize>10pt</FontSize>
                <FontWeight>Bold</FontWeight>
                <Color>DarkOliveGreen</Color>
                <BackgroundColor>LightSalmon</BackgroundColor>
                <BorderStyle>
                    <Default>Solid</Default>
                </BorderStyle>
                <BorderColor>
                    <Default>DimGray</Default>
                </BorderColor>
            </Style>
            <Style Name="Detail">
                <FontFamily>Tahoma</FontFamily>
                <FontSize>10pt</FontSize>
                <FontWeight>Bold</FontWeight>
                <Color>White</Color>
                <BackgroundColor>LimeGreen</BackgroundColor>
                <BorderStyle>
                    <Default>Solid</Default>
                </BorderStyle>
                <BorderColor>
                    <Default>DimGray</Default>
                </BorderColor>
            </Style>
        </Styles>
    </StyleTemplate>

    You can of course include several sets of Style-Templates.

    How to test?

    Just run the “Add new Report”-wizard from inside BIDS, and you will see your own style appear in the list. Unfortunately there will be no picture-preview for user defined styles, so use a descriptive name.

    image

    And again, just like the Layout Templates, you could xcopy deploy this folder to all your Developers machines.

    How about “centralizing”?

    • Just as Report Layout Templates you can “xcopy deploy” this folder regularly to all your Developers machines.
    • But again: once the reports are created, and you make a change to the originating template, existing reports will not be touched.

    How about “standardizing”?

    • If you “xcopy deploy” this folder regularly to all your Developers machines, all developers can easily use the same colors and fonts for newly created tables & matrixes.

    In short: What Style-Templates can be used for:

    • If you like using the „New Report“-wizard for quickly starting a report:
    • Have the first Table or Matrix finalized with the corporate-design colors and font-styles
    • Includes a report-title and body-color

    Note:

    • Does NOT apply to elements added thereafter
    • Once the report is created, the style is hard-coded

     

    References:

    the only reference with code samples on the web is this post from 2004 here by a Microsoft guy:
    http://www.ms-news.net/f3037/styletemplates-xml-tags-2920674.html#post9344712

    The second link I’ll provide just gives a general overview over the two methods “Report (Layout) Template” and “Report Style Template”:
    http://blogs.microsoft.co.il/blogs/yanivy/archive/2010/08/03/create-custom-templates-and-styles-for-ssrs-2008.aspx

     

    In the next Part of the series, I will show how to use custom code for managing style.

    Andreas

    Sarpedon Quality Lab

    Standardizing and Centralizing Report Design (or: creating style sheets for reports) Part 2: The Layout-Template

    As a first technique in this series we will look at what I will call “Layout template”.

    I chose the Term “Layout-Template” for two reasons:

    first: the main thing that they can be used for is, to define general report sizing, footer and header elements – in other words, the overall layout of the report.

    secondly: in the next part of this series we will see a different type of template which will actually be called “Style-Template”.

     

    So, what is a Layout-Template?:

    A Report Template can be as simple as a standard report with a certain page width and height, certain colors, a standard company logo etc., which can be copied over and over again.

    Here the Problem is, how to avoid to overwrite the defined Report Template unintentionally, and, how to make it easily available.. even (report-)project-independent.

    And this is where “Layout-Templates” come at hand.

     

    Report Layout-Templates are shown in the Project-Dialogue “Add“ – “New Item“ .

    image

    There you can choose a Template and it will create a copy local to your project – and not overwrite the Rdl at its original location.

    And this is how we create a Report Layout-Template:

    1) Simply create a regular report, configure size, header and footer and so on. You could create a data region, but it would make little sense – just as a sample maybe.

    2) Then you put the .rdl-file in the following location:

    for Reporting Services 2005

    • %ProgramFiles%\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\ProjectItems\ReportProject

    for Reporting Services 2008 x64

    • %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\ProjectItems\ReportProject

    for 32-bit Reporting Services 2008

    • C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\ProjectItems\ReportProject

    3) and when you right-click at the reports-node in your project, click “Add“ and then chose “New Item“, your Report Templates will appear in the “Add New Item” box:

    image

    That’s it. Very simple.

    How about “centralizing”?

    • You can “xcopy deploy” this folder regularly to all your Developers machines.
    • But: once the reports are created, and you make a change to the originating template, existing reports will not be touched.

    How about “standardizing”?

    • If you “xcopy deploy” this folder regularly to all your Developers machines, all your reports should have the same Layout in terms of sizing, header&footer.

    In short: What Layout-Templates can be used for:

    • Having predefined report size, (i.e. landscaped and portrait version)
    • Include report-header and footer with corporate design and navigational elements
    • Can even include sample data-regions with appropriate fonts and colors

     

    In the next Part of the series, you will see how to create and use a Style-Template.

    Andreas

    Sarpedon Quality Lab

    Standardizing and Centralizing Report Design (or: creating style sheets for reports) Part 1: The possibilities

    While SQL Server 2011 (Denali) is at horizon, bringing up many changes in the way reports will be developed, Developers using SQL Server 2005, 2008 or 2008 R2 are still faced with on problem from the very first report on: How can I make not only development easier by having a template for reports at hand, but also, how to manage it.

    Whereas in the area of webdesign, it is absolutely common to have a (cascading) style sheet to be referred to in all website-documents, in reporting services this concept does not exist.
    While this is very annoying and it seems that it should be easy to implement at first, one has to remember, that Reporting Services does not just render to html, but at the same time Reporting Services have to be equally prepared to render Reports to Excel-Files, pdf-Files, TIFF-Image-Files, among others. So using the same technique as websites do, would simply to narrow.
    There is a case at Microsoft Connect, where you can vote on this feature to get implemented in an upcoming version: http://connect.microsoft.com/SQLServer/feedback/details/253976/add-style-or-stylesheet-or-template-to-reporting-services-reports

    In short: In Reporting Services there is no such one thing as ONE and only style sheet that does all magic for you.
    This blog-series is intended to show you the existing techniques, and how to combine them. In the end your effectiveness in creating an managing Reports style-wise can be improved by a magnitude. But: there is work to do beforehand.

    I spend quite a while, reading other blogs, the rare documentation and doing my own tests. Finally I had the honor of presenting a whole session on this matter at the European PASS Conference 2009.

    In the following posts I will concentrate on the existing techniques I identified as the most useful techniques and combination.

    Those are the techniques I will focus on:

    The Basic Techniques:

    Custom methods:

    • Using Custom Code
    • Using an Assembly
    • Using plain T-SQL

    Combining techniques:

    • Style Template + Layout Template
    • Style Template + Custom style + Layout Template

    Reporting Services 2008 R2 techniques

    • Shared DataSet
    • Report Part

     

    I also tested using XML-Files as well as making a webservice-call to get Style-data, but this turned out to be rather pathological and is therefore left out from further consideration.

    In the next Part of the series, I will show how to create and use a Layout-Template.

     

    Andreas

    Sarpedon Quality Lab

    Preview of SQL Server 2011, Codename Denali CTP 1 presented at PASS Summit 2010 in Seattle

    Sql_Server_2011_Denali

    This year’s PASS Summit again surpassed the former year’s one. And this was not only because of even more sessions, internationally well-known speakers and even more attendees. This November, the next release of SQL Server was officially being introduced to the public, and the first CTP is ready for download for the broad public.

    The improvements and features are enormous. Developers can look forward to a new Development Environment (Project Juneau), and new capabilities and performance using the new Filetable-Feature, as well as super fast response through the new Column-Based Query Accelerator technology.

    Analysis Services will be receiving a new engine, based on the Vertipaq (known from PowerPivot), called BI Semantic Model for easier development for less complex BI Projects. (The UDM will stay as an alternative)
    Here is a link to the Technet article on “Analysis Services – Roadmap for SQL Server “Denali” and Beyond”.

    Integration Services ware becoming a true windows service for central execution and management.

    image

    Reporting Services users and developers can look forward to an web-integrated report designer together with interactive and dynamic charts. (Project Crescent)

    Administrators gain new possibilities regarding security with customizable Server roles and database-only users. Database-only users are especially meant to support the new “Contained database”-Feature, which eases the deployment and movement of databases together with the depending objects from server scope.
    (You can find a good high-level overview on the log-on process of database-only users at this msdn blog-post: http://blogs.msdn.com/b/sqlsecurity/archive/2010/12/08/contained-database-authentication-in-depth.aspx. And here is a great blog-post, going through different scenarios with this feaure: http://sqlblog.com/blogs/aaron_bertrand/archive/2010/11/16/sql-server-v-next-denali-contained-databases.aspx.)

    High Availability will be eased by combining the log-shipping, database-mirroring and Clustering features under a new concept of “Always on” technologies, which can be used to form a so called “Availability Group”.

    Steffen Krause from Microsoft Germany has some more info on the Denali release and also shows demos in his webcasts: http://blogs.technet.com/b/steffenk/archive/2010/11/15/sql-server-denali-ctp-1-verf-252-gbar-was-ist-neu.aspx

    If you want to check out the CTP yourself, here is the link: http://www.microsoft.com/sqlserver/en/us/product-info/future-editions.aspx

    Enjoy,

    Andreas

    Sarpedon Quality Lab

    Security-issue: guest-guest impersonation

    Almost a year ago I discovered an issue with SQL Server (all Versions from 2005 – 2008 R2, haven't tested 2000) regarding the usage of the guest-account and impersonation.

    It also was presented by Ralf Dietrich and me at the SQL Server PASS Summit 2009 in Seattle where we informed Microsoft about it. - Thanks to Jack Richins from Microsoft for helping me find the root cause. (MSDN-blog post)

    Unfortunately, a fix hasn’t been provided for SQL Server yet. As I was informed it will only be fixed in the next major version, Codename “Denali”. Here is the Connect-Item: https://connect.microsoft.com/SQLServer/feedback/details/509379/guest-activated-in-2-databases-leads-to-inconsistent-behaviour-and-may-also-compromise-security

    Recently I demonstrated this technique again at the SQLCon in Mainz/Germany and now feel that I should blog about this.

     

    This issue applies in a couple of scenarios, a more common of which I want to show here.

     

    One scenario is, that sometimes or even often, developers, whether external or not, are given excessive rights in a certain database – on the same Server, where other databases exists, which may contain “public” data. But “public” maybe only for internal usage and not for external developers.

    This is accomplished the following way: the database, let’s call it “InternalPublicData” will have the guest account enabled, and guest has permissions to see whatever is of interest for internal stuff.

    In order to prevent access to this database for a certain Login, a database-user will be explicitly created in this database, so the Login does not match to guest and will be denied any resources in this database. One could even deny Connect-permission to the database, to secure it even more.

    But this doesn’t help either, as you will see.

    Also there is the database where the developer will have full permissions so he can work in his database and do anything inside. He might be dbo or member of the db_owner-role. (Unfortunately quite common because of the restrictions when using db_ddladmin etc.)

    And now the trouble begins: The developer, let's call him “Dev0” cannot successfully connect to the InternalPublicData-database and act as guest there. But what he can do is the following: he can enable guest in his very own database.

    Doing that, he can impersonate his local guest and then, not being “Dev0” any more, go to the InternalPublicData-database and successfully connect.

    At that stage, he already has all permissions that the remote guest-account already has directly attached to it. But that’s not all. He can then do a second impersonate and gain role-memberships of the guest at the InternalPublicData-database!

    No "Deny" for Dev0 can prevent that!

     

    As a second option, he could, with permissions of creating a “User without Login“, impersonate that User and use it to jump to other databases where guest-is active…

     

    The following is a script to demonstrate:

    --Login:
    CREATE LOGIN Dev0
        WITH PASSWORD = 'Pa$$w0rd'
    GO

    /* setup DBs*/
    create database InternalPublicData;
    create database DevelopmentDB;
    GO

    --Target-DB
    use InternalPublicData;
    grant connect to guest;

    create table t1(c1 int)
    insert into t1 values(1)

    create table t2(c1 int)
    insert into t2 values(2)

    GRANT SELECT
    ON dbo.t1
    TO guest    -- and only guest

    exec sp_addrolemember 'db_datareader', 'guest'    -- just to point out the fact that these guest-accounts are actually different even further

    CREATE USER Dev0 FOR LOGIN Dev0    -- no memberships, so denied everything and not matching to guest automatically

    DENY CONNECT TO Dev0    -- to make SURE!

    -- DB 2
    use DevelopmentDB;

    CREATE USER Dev0 FOR LOGIN Dev0

    EXEC sp_addrolemember N'db_owner', N'Dev0'
    GO

    GO

    /* Setup finish */

    /* Session as Dev0 */

    EXECUTE AS LOGIN = 'Dev0'

    -- Who and Where am I
    SELECT CURRENT_USER AS CURRENT_USER_Name
        , SYSTEM_USER AS SYSTEM_USER_Name
        , ORIGINAL_LOGIN() AS ORIGINAL_LOGIN_Name
        , DB_NAME() AS Current_Database

    use InternalPublicData;    -- not possible with Deny Connect

    SELECT * FROM t1    -- with no Deny connect he gets denied here

    execute as user = 'guest';        -- he can NOT do this at the remote DB (good so far)

    -- Part One:

    -- go back
    USE DevelopmentDB

    execute as user = 'guest';        -- not active

    grant connect to guest;    -- but as a "Dev" with excessive permissions he can do what he wants
    exec sp_addrolemember 'db_datawriter', 'guest'    -- just so that one can differentiate the guest accounts easier

    execute as user = 'guest';        -- now we are in the game

    -- Who and Where am I
    SELECT CURRENT_USER AS CURRENT_USER_Name
        , USER_NAME()    AS DBUser
        , SYSTEM_USER AS SYSTEM_USER_Name
        , ORIGINAL_LOGIN() AS ORIGINAL_LOGIN_Name
        , DB_NAME() AS Current_Database

    select * from sys.user_token;    -- now he became guest in DevelopmentDB for real

    -- End of Part One

    -- Part Two: using guest for executing as guest

    USE InternalPublicData;        -- we connected as guest - no Deny for Dev0 Applying!!

    SELECT CURRENT_USER AS CURRENT_USER_Name
        , USER_NAME()    AS DBUser
        , SYSTEM_USER AS SYSTEM_USER_Name
        , ORIGINAL_LOGIN() AS ORIGINAL_LOGIN_Name
        , DB_NAME() AS Current_Database
    select * from sys.user_token;    -- he became guest in the remote-DB

    SELECT * FROM dbo.t1        -- permissions at User(guest)-Level already working!

    SELECT * FROM dbo.t2        -- not working because permission for role not applying

    -- BUT: switch to InternalPublicData guest explicitely
    execute as user = 'guest';        --NOW "Dev0" can do it in the Target-DB

    SELECT CURRENT_USER AS CURRENT_USER_Name
        , USER_NAME()    AS DBUser
        , SYSTEM_USER AS SYSTEM_USER_Name
        , ORIGINAL_LOGIN() AS ORIGINAL_LOGIN_Name
        , DB_NAME() AS Current_Database
    select * from sys.user_token;    -- he became guest with group-membership in Target-DB

    SELECT * FROM dbo.t2            -- can now also read datathrough role-membership

    -- End of Part Two: using guest for executing as guest
    /* back off step by step */

    USE InternalPublicData
    revert;

    USE DevelopmentDB
    revert;

    revert;

    USE InternalPublicData
    revert;

    /* Finished */

    USE master;
    DROP DATABASE InternalPublicData;
    DROP DATABASE DevelopmentDB;
    DROP LOGIN Dev0

     

    There is just one option to be sure that your system is safe from developers: don’t mix production with development – not even on server-level!

    This should be absolutely clear, but I’ll repeat that, as long as I see mixed environments at customers' sites. Unfortunately, this is very common.

    And secondly: never use the guest account for data that is not really supposed for everyone.

     

    Sarpedon Quality Lab

    HighLevelTraining.de

    Scripting Table Data with SQL Server 2008 R2

    I recently was asked, whether the Feature “Script Data” as T-SQL-command INSERT INTO… has been removed in SQL Server 208 R2.

    In fact, it was not visible on first sight.

    This is how you can find it:

    It is still the right-click “Tasks” - “Generate Scripts” –Wizard.

    After having chosen the Table(s), the following window appears:

    SQL_2008R2_Set_Scripting_Options

    there click “Advanced” and scroll down inside the “General”-part until the Element “Types of data” to script

    image

    And there under the following drop-down, it is hidden:

    Types_of_data_to_script_drop_down

    And the German translation “Datentypen, für die ein Skript erstellt wird”, makes it even harder to detect:

    Erweitere_Skriptoptionen

    Conclusion: Scripting out Data with “INSERT INTO”-commands is a bit hidden – (under SQL 2008 it was under the “Table/View Options”, now under “General” – “Types of data to script”) but still available :-)

     

    www.andreas-wolter.com

    Addresses for geographical Data, ESRI-Shapefiles and other SQL Server geographical related stuff

    SQL Server 2008 R2 Reporting Services supports the visualization of geographical data in 3 ways.

    • Datasets, based on the built-in .Net System-datatypes “geography” and “geometry”, which have been around since SQL Server 2008
    • via built-in maps – but only for the United States
    • via ESRI-Shapefiles, which one has to provide on his own

    Now, where can you get those Shape-files?

    Other, than in the USA where gathered data belongs to the people, with no cost (Census Bureau Geography), in other countries, such as in Germany, it is by far not easy, to even get such datat all.

    In the following, I am collecting internet-sites, where one can find geographical data. I'd be happy to include more URLs, if you found a good one, to share.

     

    Spatial Data at MIT
    http://libraries.mit.edu/gis/data/index.html
    several links to other map-data, even outside US
    MapCruzin.com
    http://www.mapcruzin.com/...
    free maps from around the world. political as well as physical, some even down to street-/building-level
    Natural Earth
    http://www.naturalearthdata.com/downloads/
    several maps of the world with borders and physical structure
    Bundeswahlleiter
    http://www.bundeswahlleiter.de/...
    maps of German "Wahlkreise", nice to play around with. They even include votes per area
    http://www.datendieter.de various kinds of  datasets, also geographical, mainly German – mostly for a fee, but some is also free
       

    Miscellaneous:

    Other:

    MsSQLSpatial http://mssqlspatial.codeplex.com/ spatial datatype-extension for SQL Server 2005
    Spatial Tools with Shapefile Uploader

    http://www.sharpgis.net/page/SQL-Server-2008-Spatial-Tools.aspx

    Tools for importing ESRI-Shapefiles into SQL Server as well as for looking at the data

     


    Further good articles concerning geographical data and SQL Server:

    Creating your own SSRS map using Visio

    http://blog.oraylis.de/2010/07/creating-your-own-ssrs-map-using-visio/

    Using Visio and SSRS Map Reports for Store Layouts etc.

    http://blog.oraylis.de/2010/06/using-visio-and-ssrs-map-reports-for-store-layouts-etc/

    Using ESRI ShapeFiles with SSI

    http://ssis-components.net/post/2010/04/11/ESRI-ShapeFiles-verarbeiten.aspx

    For importing shape-files into SQL Server, see this blog-post at MSDN: http://blogs.msdn.com/seanboon/archive/2009/11/17/sql-server-2008-r2-map-tips-how-to-import-shapefiles-into-sql-server-and-aggregate-spatial-data.aspx

    Achieve Spatial Data Support in SSIS:
    http://www.sql-server-performance.com/articles/biz/spatial_data_support_ssis_p1.aspx

    Bridge The Gap between Bing and Google Maps using SSIS
    http://www.sql-server-performance.com/articles/biz/bing_google_maps_p1.aspx 

    Heat Maps as Reports

    http://prologika.com/CS/blogs/blog/archive/2009/08/30/heat-maps-as-reports.aspx

    Stacia Misner shows in her blog, how to include your maps in the Map-Gallery for the Map-Builder-Wizard:

    http://blog.datainspirations.com/2010/08/31/do-it-yourself-map-gallery-in-sql-server-2008-r2-reporting-services/

    Rob Farley shows, how you can geocode you address-data using bing-maps and powershell:

    http://sqlblog.com/blogs/rob_farley/archive/2010/05/23/fetching-latitude-and-longitude-co-ordinates-for-addresses-using-powershell.aspx

     

    Have fun with Reporting Services 2008 R2

    Andreas


    Sarpedon Quality Lab

    Integration Services: Looping & “continue on error”

     

    Eine häufige Aufgabe bei der Arbeit mit Integration Services Paketen ist es, eine Routine in einer Schleife auszuführen.

    Nehmen wir den konkreten Fall: ein For Each-Loop zum rekursiven Auslesen von Textdateien aus einer Verzeichnisstruktur und Verschieben an einen Zielort.

    Wenn die Operation aufgrund von einer geöffneten Datei (z.B. der Log-Writer Prozess) fehlschlägt, schlägt damit der Task “Move file” fehl. Sodann der Container “For Each Loop”, und dann das gesamte Paket. Das ist das Standardverhalten: das Event “Error” wird propagiert.

    Das sieht in etwa so aus (hier mit einen For Loop):

    SSIS_EventPropagation_standard

    Man sieht trotz der versuchten “Fehlerbehandlung” in dem Script-Task “SCR-Fail” schlägt der Container fehl.

    Das ist in diesem Fall aber nicht unbedingt das gewünschte Ergebnis.
    Man möchte, das die Operation einfach mit der nächsten Datei fortfährt und eventuell liegengebliebene Dateien in einem späteren Durchlauf einfach holen.

    Dafür muss man das propagieren des Fehlers auf Container-Ebene unterbinden. Die dafür extra vorhandene Systemvariable “Propagate” ist ausnahmsweise deswegen auch manuell änderbar. Allerdings gibt es diese nur in den Event Handlern.

    Das heisst für den fehlschlagenen SQL-Task in diesem Beispiel ist ein EventHandler für “OnError” anzulegen. Dort findet man dann die besagte Variable und schaltet sie auf False

    SSIS_EventPropagation_SystemVariablePropagate 

     

    Das würde an sich schon genügen, um das Paket einfach weiterlaufen zu lassen.

    Allerdings ist es in der Regel wünschenswert, im Anschluss eine bedingte Reaktion auf das erfolgreiche oder erfolglose Verschieben der Datei erfolgen zu lassen. In diesem Beispiel ein T-SQL-Schritt bei Erfolg, und der Script-Task “Fail” bei Misserfolg.

    Da nun kein Fehler mehr propagiert wird, ist ein kleiner Kunstgriff vonnöten: Man definiert sich eine Variable, welche im Fehlerfall einen anderen Wert erhält und liest diese dann bei dem Precedence-Constraint zusätzlich mit aus.

    Am einfachsten geht das mit dem im Fehlerfall ohnehin vorhandenen ErrorCode – innerhalb des EventHandler natürlich.

    Dort leitet man den Wert der Systemvariable “ErrorCode” einfach in seine eigens zuvor angelegte User-Variable um:

    Dts.Variables("User::ErrorCode").Value = Dts.Variables("System::ErrorCode").Value

    Im ControlFlow wird dann ein “OnCompletion” – Precedence Constraint verwendet, und zusätzlich die Variable in der Expression "@[User::ErrorCode] != 0" ausgewertet

    Das gewünschte Ergebnis verhält sich dann so:

    SSIS_EventPropagation_Result

    Der Fehler im Task wird abgehandelt, und die Arbeit wird fortgesetzt.

     

    happy coding :)

     

    Andreas Wolter


    Sarpedon Quality Lab

    Mehr Beiträge Nächste Seite »