Parse CustomerMaintenanceNotifications from MessageLog

with xmlnamespaces('urn:mining.sandvik.com:CustomerManagement:GlobalDataTypes' as ns1)
select
inputmessage, cast(replace(cast(inputmessage as nvarchar(max)), 'encoding="UTF-8"', '') as XML).value('(/ns1:CustomerMaintainNotification/Customer/Locations/Location[1]/BusinessRelations/BusinessRelation[1]/ERPStatus/Code/node())[1]', 'nvarchar(255)') AS 'ERP Status'
from MessageLog
where
date > '2017-09-26 14:00:10'
--and date < '2017-09-25 14:25:00' and siteid = 'Authorization' and category='Backend' --and inputmessage like '%105372%' and outputmessage not in ('Processed message: EquipmentMaintainNotification') --order by date desc

Select values from XML in TSQL

with xmlnamespaces(default 'urn://com.sandvik.smc.doc.connect/1.0')
select
m.[date] AS Date,
cast(replace(cast(m.inputmessage as nvarchar(max)), 'encoding="UTF-8"', '') as XML).value('(/acknowledge_sales_order/data_area/sales_order/sales_order_header/sales_order_hdr_process/order_source_descriptor/order_source/node())[1]', 'nvarchar(255)') AS 'Order Source',
cast(replace(cast(m.inputmessage as nvarchar(max)), 'encoding="UTF-8"', '') as XML).value('(/acknowledge_sales_order/data_area/sales_order/sales_order_header/sales_order_hdr_basic/sop_company_1/node())[1]', 'nvarchar(255)') AS Company,
cast(replace(cast(m.inputmessage as nvarchar(max)), 'encoding="UTF-8"', '') as XML).value('(/acknowledge_sales_order/data_area/sales_order/sales_order_header/sales_order_hdr_basic/order_number_7/node())[1]', 'nvarchar(255)') AS 'Order Number'
from
messagelog m
where
date > '2016-10-01 00:00:00'
and OutputMessage = 'Processed message: ACKNOWLEDGE_SALES_ORDER'
order by
date desc

Dumping columns to files with Microsoft SQL Server >2012


DECLARE @xml NVARCHAR(MAX);
DEClARE @ID INT;
DECLARE @filename NVARCHAR(1024);
DECLARE @sqlStr NVARCHAR(1024);
DECLARE @sqlCmd NVARCHAR(1024);

DECLARE meh CURSOR FOR
select InputMessage, Id from messagelog where date > '2016-02-05' and outputmessage like '%Unknown message: Equipment%' order by date desc;

OPEN meh
FETCH NEXT FROM meh INTO @xml, @ID

WHILE @@FETCH_STATUS = 0
BEGIN
SET @filename = 'C:\temp\EquipmentMaintainNotification_' + CAST(@ID AS NVARCHAR) + '.xml';
PRINT @filename
SET @sqlStr = 'USE SIBP_Logging;SELECT InputMessage FROM MessageLog WHERE Id = ' + CAST(@ID AS NVARCHAR);

SET @sqlCmd = 'bcp "' + @sqlStr + '" queryout "' + @filename + '" -w -T -S SEDNT2434\DEV'
PRINT @sqlCmd

EXEC xp_cmdshell @sqlCmd

FETCH NEXT FROM meh INTO @xml, @ID
END
CLOSE meh
DEALLOCATE meh

Excel: Get Department from Active Directory


Function GetDepartment(strAccountName As String, strDomainName As String)
Dim adoLDAPCon As ADODB.Connection
Dim adoLDAPRS As Recordset
Dim strLDAP As String

If strAccountName = "" Or strAccountName = "-" Then
GetDepartment = "invalid input"
Exit Function
End If

Set adoLDAPCon = CreateObject("ADODB.Connection")
adoLDAPCon.Provider = "ADsDSOObject"
adoLDAPCon.Open "ADSI"
strLDAP = "'LDAP://" & strDomainName & "'"

Set adoLDAPRS = adoLDAPCon.Execute("select department from " & strLDAP & " WHERE objectClass = 'user'" & " And samAccountName = '" & strAccountName & "'")
With adoLDAPRS
If Not .EOF Then
GetDepartment = .Fields("department")
Else
GetDepartment = "not found"
End If

End With
adoLDAPRS.Close
Set adoLDAPRS = Nothing
Set adoLDAPCon = Nothing

End Function

SQL for fixing faulty composer pages

DECLARE c CURSOR READ_ONLY FAST_FORWARD FOR
-- select MAX(pkID) as MaxID from tblWorkPage where fkPageID = 22493 group by fkLanguageBranchID
select MAX(b.pkID) from
(select MIN(a.fkPageID)as minid, MIN(a.fkLanguageBranchID) as minbranch from tblworkpage a
left join tblProperty b
on a.fkPageID = b.fkPageID
and a.fkLanguageBranchID = b.fkLanguageBranchID
and b.LongString like '%

Lazy Loading Asyncronous Javascript

from http://friendlybit.com/js/lazy-loading-asyncronous-javascript/#comments

(function() {
function async_load(){
var s = document.createElement(‘script’);
s.type = ‘text/javascript’;
s.async = true;
s.src = ‘http://yourdomain.com/script.js’;
var x = document.getElementsByTagName(‘script’)[0];
x.parentNode.insertBefore(s, x);
}
if (window.attachEvent)
window.attachEvent(‘onload’, async_load);
else
window.addEventListener(‘load’, async_load, false);
})();

Debugging IIS with WinDBG

windbg

attach to process – w3wp

-.sympath srv*http://msdl.microsoft.com/download/symbols
-.reload
-.load c:\windows\microsoft.net\framework\v2.0.50727\sos.dll
-!threads – this is an SOS command and it succeeds.

!runaway – se cputid för alla trådar
~#s välja tråd, där # är trådid
!clrstack – visa .net stacken