use master
go
IF NOT EXISTS ( SELECT TOP 1 1 FROM master.sys.sysobjects WHERE type='U' AND name='ServerLoginHistory' )
BEGIN
CREATE TABLE [dbo].[ServerLoginHistory]
(
[SystemUser] [varchar](512) NULL,
[HostName] [varchar](512) NULL,
[DBUser] [varchar](512) NULL,
[SPID] [int] NULL,
[LoginTime] [datetime] NULL,
[AppName] [varchar](512) NULL,
[DatabaseName] [varchar](512) NULL
)
END
GO
IF EXISTS (SELECT * FROM master.sys.server_triggers WHERE parent_class_desc = 'SERVER' AND name = N'tr_ServerLoginHistory')
BEGIN
DROP TRIGGER [tr_ServerLoginHistory] ON ALL SERVER
END
GO
CREATE TRIGGER [tr_ServerLoginHistory]
ON ALL SERVER WITH EXECUTE AS 'sa'
FOR LOGON
AS
BEGIN
IF ORIGINAL_LOGIN() NOT IN ( 'NT AUTHORITY\SYSTEM' )
BEGIN
INSERT INTO [ServerLoginHistory]
SELECT ORIGINAL_LOGIN(), HOST_NAME(),USER, @@SPID, GETDATE(), APP_NAME(), DB_NAME()
END
END --tr_ServerLoginHistory
GO
ENABLE TRIGGER [tr_ServerLoginHistory] ON ALL SERVER
GO
--DISABLE TRIGGER [tr_ServerLoginHistory] ON ALL SERVER
--GO
Friday, October 10, 2014
Login History Server Trigger
Saturday, September 6, 2014
how to tell collation
SELECT
DATABASEPROPERTYEX('[DBNAME]', 'Collation') DBCollation
, SERVERPROPERTY ('Collation') "ServerCollation";
Wednesday, July 30, 2014
apache2
Notes for managing vhosts on apache2 (Apache 2.2.16 Ubuntu)
Add new vhosts:
1. create folder for site in /var/www/vhosts/
2. create vhost file in /etc/apache2/sites-available
3. create ln to sites-available file from sites-enabled
4. Restart Apache
/etc/init.d/apache2 restart
To check version:
apache2ctl -v or apache2 -v
Add new vhosts:
1. create folder for site in /var/www/vhosts/
2. create vhost file in /etc/apache2/sites-available
3. create ln to sites-available file from sites-enabled
4. Restart Apache
/etc/init.d/apache2 restart
To check version:
apache2ctl -v or apache2 -v
Friday, July 18, 2014
Steps to clean install new Mule ESB server version
- unregister old version in MMC
- mule stop
- mule remove
- archive old version folder
- remove old version folder
- unzip new version of mule
- Change %MULE_HOME% environmental variable to point to new version
- start new command shell
- check echo %MULE_HOME% to confirm value set to new version
- mule -installLicense licensefile.lic
- mule install
- mule start
- register new version in MMC
- deploy mule apps
Find OS User for command shell spawn from SQL Server context
If the policy on the server allows execution of xp_cmdshell then can find out the windows user that owns the spawned shell to handle OS commands executed from within sql server context
EXEC xp_cmdshell 'whoami'
to get the value into a variable can do following
DECLARE @whoisit nvarchar(4000)
CREATE TABLE #test ( output nvarchar(4000) null )
INSERT INTO #test (output)
EXEC xp_cmdshell 'whoami'
SELECT top 1 @whoisit = output
FROM #test
WHERE output IS NOT NULL
SELECT @whoisit "whoisit"
DROP TABLE #test
Thursday, July 17, 2014
Permission paths for login
You can look for the permission paths used by a login as follows:
EXEC xp_logininfo 'DOMAIN\USER_A', 'all'
Wednesday, June 25, 2014
SQL Server 2012: Kill all processes for a specific database
SELECT 'KILL ' + cast(A.session_id as varchar)
FROM sys.dm_exec_sessions A WITH (NOLOCK)
INNER JOIN sys.databases B WITH (NOLOCK)
ON A.database_id = B.database_id
WHERE B.name = 'your.dbname.here'
Subscribe to:
Posts (Atom)