Tuesday, March 28, 2017

SQL Server - what is each session doing? running? sleeping?



SELECT s.status, s.session_id, '################', * FROM sys.dm_exec_sessions s ORDER BY s.status;

The current Session is:

SELECT @@SPID;

It will always be running, or queries wont work.

SQL Server - Show open transactions



SELECT * FROM sys.dm_tran_session_transactions;

Monday, March 27, 2017

SQL Server - Is there an open transaction on a session_id?




-- Is there an open transaction on a session_idSELECT  st.transaction_id,
  at.name,
  at.transaction_begin_time,
  at.transaction_state,
  at.transaction_status
FROM    sys.dm_tran_session_transactions st
  JOIN    sys.dm_tran_active_transactions at    ON st.transaction_id = at.transaction_id
WHERE   st.session_id = 52;--your blocking spid

SQL Server - What was the last statement on a session_id




-- What was the statement on a session_idSELECT  c.session_id, t.text,
  QUOTENAME(OBJECT_SCHEMA_NAME(t.objectid, t.dbid)) + '.'  + QUOTENAME(OBJECT_NAME(t.objectid, t.dbid)) proc_name,
  c.connect_time,
  s.last_request_start_time,
  s.last_request_end_time,
  s.status
FROM    sys.dm_exec_connections c
  JOIN    sys.dm_exec_sessions s    ON c.session_id = s.session_id
  CROSS APPLY sys.dm_exec_sql_text(c.most_recent_sql_handle) t
WHERE   c.session_id = 52;--your blocking spid


SQL Server find out what is blocking what, or find a dead lock

Use this query, but you must be serveradmin to run it:

SELECT  db.name DBName,
  tl.request_session_id,
  wt.blocking_session_id,
  OBJECT_NAME(p.OBJECT_ID) BlockedObjectName,
  tl.resource_type,
  h1.TEXT AS RequestingText,
  h2.TEXT AS BlockingTest,
  tl.request_mode
FROM sys.dm_tran_locks AS tl
  INNER JOIN sys.databases db ON db.database_id = tl.resource_database_id
  INNER JOIN sys.dm_os_waiting_tasks AS wt ON tl.lock_owner_address = wt.resource_address
  INNER JOIN sys.partitions AS p ON p.hobt_id = tl.resource_associated_entity_id
  INNER JOIN sys.dm_exec_connections ec1 ON ec1.session_id = tl.request_session_id
  INNER JOIN sys.dm_exec_connections ec2 ON ec2.session_id = wt.blocking_session_id
  CROSS APPLY sys.dm_exec_sql_text(ec1.most_recent_sql_handle) AS h1
  CROSS APPLY sys.dm_exec_sql_text(ec2.most_recent_sql_handle) AS h2;

Wednesday, February 1, 2017

Windows File Sharing

Some bits here are guesses

A machine will not necessarily let another machine see the files on it at all.
Under network and sharing center, go to advanced sharing and let it share with guest or public machines.
I believe this allows other machines to initiate sharing, but some sort of permissions may still prevent sharing - even if sharing for everyone has full control.

On the machine trying to access the files on the remote machine you can have it use credentials to get access.
Go to Credential Manager -> Windows Credentials
Add the remote machine by ip name or ip number.
Add an account and password that has permissions on the remote machine.

For some minimal level of security, make an account on the remote file machine for file sharing.
Only give it access to the shared directory.
Use that accounts credential in Credential Manager.

Monday, January 30, 2017

Install .NET 3.5 on Windows 10

I couldn't get this to work in any of the standard ways.
I mounted my Windows 10 installation media on M:\
I ran this command:

dism /online /enable-feature /FeatureName:NetFx3 /All /LimitAccess /Source:M:\sources\sxs

It worked!

I looked at the Windows Features tree and saw that 3.5 was now there.