Skip to content

Instantly share code, notes, and snippets.

@rusanu
rusanu / ncrypt-module.psm1
Created January 23, 2018 07:09
NCrypt module
$apiDefinition = @'
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
public class NCryptApi
{
//public const NCRYPT_MACHINE_KEY_FLAG = ;
//public const NCRYPT_NAMED_DESCRIPTOR_FLAG = ;
@rusanu
rusanu / dump_all_sql_connections.txt
Created September 21, 2017 14:47
Windbg script to dump all SqlConnections and last packet sent to server from dump or process
$$ First find the MT of System.Data.SqlClient.SqlInternalConnectionTds
$$
r @$t9=0
.foreach(obj {!dumpheap -mt <MT> -short}) {
r @$t9=@$t9+1
.printf /D "%i <link cmd=\"!do %p\">%p</link> ", @$t9, ${obj}, ${obj}
r @$t0 = poi(${obj}+98)
.printf /D "<link cmd=\"!do %p\">%p</link> ", @$t0, @$t0
r @$t0 = poi(@$t0+8)
.printf /D "<link cmd=\"!do %p\">%p</link> ", @$t0, @$t0
<?xml version="1.0" encoding="utf-16"?>
<ShowPlanXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.2" Build="11.0.3128.0" xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan">
<BatchSequence>
<Batch>
<Statements>
<StmtSimple StatementCompId="1" StatementEstRows="1000000" StatementId="1" StatementOptmLevel="FULL" StatementSubTreeCost="62.1708" StatementText="insert [dbo].[foo] select * from [dbo].[foo]" StatementType="INSERT" QueryHash="0x5C849102FA5C1003" QueryPlanHash="0xEF52C9161E6E3B36" RetrievedFromCache="false">
<StatementSetOptions ANSI_NULLS="true" ANSI_PADDING="true" ANSI_WARNINGS="true" ARITHABORT="true" CONCAT_NULL_YIELDS_NULL="true" NUMERIC_ROUNDABORT="false" QUOTED_IDENTIFIER="true" />
<QueryPlan DegreeOfParallelism="4" MemoryGrant="90248" CachedPlanSize="16" CompileTime="369" CompileCPU="366" CompileMemory="136">
<ThreadStat Branches="1" UsedThreads="4">
<Th
@rusanu
rusanu / README.md
Last active August 29, 2015 14:04
The Accidental DBA (SQL Server)

Work in progress.

Who

I am a developer with my company. I like to learn new things so I snooped at our SQL Server instance. In no time I ended being the 'go to' person for it and now am a de-facto DBA. My job is still 110% dev, DBA duties are the extra percents left...

I am a sysadmin with my IT department. I was asked to take care of the SQL Server instance installed to serve the management reports. I read some things about SQL Server administration and I'm not keeping an eye on it. I wish I could use cron jobs.

I am a PowerPivot wizard. My buddy helped my create this daily job that imports the sales into my own database. I installed the SQL Server myself.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.brush .extent {
stroke: #fff;
fill-opacity: .125;
shape-rendering: crispEdges;
}
.land {