I used to link to this
http://support.microsoft.com/default.aspx/kb/287515
But it now needs to go here
http://support.microsoft.com/en-us/kb/287515
I used to link to this
http://support.microsoft.com/default.aspx/kb/287515
But it now needs to go here
http://support.microsoft.com/en-us/kb/287515
You can use this syntax to remove any trailing slash ‘\’ to a path and add it back in if it’s a string.
# Remove slash $OutPath = $Path.TrimEnd('\') # Remove if exists and add back in $OutPath = $Path.TrimEnd('\') + '\'
I often run scripts, especially SQL Agent job scripts using SQLCMD. Moving to SQL 2014 I ran into this error: ‘JOBID’ scripting variable not defined.
I see it is because I also use a token variable in the last job step. A quick solution for me was to add the -x parameter to SQLCMD ( -x (disable variable substitution) ) as suggested as one of the workarounds here.
Here’s a couple of ways to get it via code.
/* http://sqlandme.com/2013/08/20/sql-service-get-sql-server-service-account-using-t-sql/ */ DECLARE @DBEngineLogin VARCHAR(100) DECLARE @AgentLogin VARCHAR(100) EXECUTE [master].[dbo].[xp_instance_regread] @rootkey = N'HKEY_LOCAL_MACHINE', @key = N'SYSTEM\CurrentControlSet\Services\MSSQLServer', @value_name = N'ObjectName', @value = @DBEngineLogin OUTPUT EXECUTE [master].[dbo].[xp_instance_regread] @rootkey = N'HKEY_LOCAL_MACHINE', @key = N'SYSTEM\CurrentControlSet\Services\SQLServerAgent', @value_name = N'ObjectName', @value = @AgentLogin OUTPUT SELECT [DBEngineLogin] = @DBEngineLogin, [AgentLogin] = @AgentLogin GO SELECT [servicename], [service_account] FROM [sys].[dm_server_services] GO
DESCRIPTION: SSPI handshake failed with error code 0x8009030c, state 14 while establishing a connection with integrated security; the connection has been closed. Reason: AcceptSecurityContext failed. The Windows error code indicates the cause of failure. [CLIENT: 10.12.23.345].
This can be related to an AD login account expiring and the user leaving SSMS or something running on their PC. The account eventually locks out and SQL sees this message until the user resets their password.
Answer here.
I love how top can accept a variable. You could pass it into a procedure.
DECLARE @vcOut VARCHAR(MAX), @nTop INT SELECT @nTop = 5 SELECT TOP (@nTop) @vcOut = COALESCE(@vcOut, '') + NAME + CHAR(10) FROM sys.sysdatabases PRINT @vcOut --
There is an issue with Mouse shadow in Remote Desktop. Can you follow the below steps on your Windows 2012 server.
1. Right click the start menu and choose Control panel
2. Change the View by from Category to Small icons
3. Click Mouse then Pointers tab
4. Uncheck “Enable Pointer Shadow”
(Thanks, Bobby!)
Last SPIDs, their statement, network packet size.
SELECT c.session_id, s.host_name, s.login_name, [LastStatement].[[text]], c.net_packet_size, s.login_time, s.status, d.name FROM sys.dm_exec_connections c INNER JOIN sys.dm_exec_sessions s ON c.session_id = s.session_id CROSS APPLY sys.dm_exec_sql_text(most_recent_sql_handle) AS LastStatement LEFT OUTER JOIN sys.databases d on d.database_id = [LastStatement].dbid ORDER BY s.[status], s.login_time DESC, s.[host_name] --
Apparently in my 64-bit environment I can’t execute the following command.
DECLARE @vcCmd VARCHAR(8000) SELECT @vcCmd = '"C:\Program Files\Winzip\WZZIP.exe" -es -a "E:\DATA\test.zip" "E:\DATA\test.dat"' EXEC master..xp_cmdshell @vcCmd = @vcCmd /* 'C:\Program' is not recognized as an internal or external command, operable program or batch file. */
The solution is I can execute other DOS commands, so let’s concatenate them.
DECLARE @vcCmd VARCHAR(8000) SELECT @vcCmd = 'C: && CD "C:\Program Files\Winzip\" && WZZIP.exe -es -a "E:\DATA\test.zip" "E:\DATA\test1.dat"' EXEC master..xp_cmdshell @vcCmd = @vcCmd