Thursday, October 16, 2014

ODBC: Another 32/64bit MS undocumented "feature"

There are two different ODBC Administrator runtimes on a 64-bit machine. 

The first ODBC Manager is used to manage 64-bit data sources, while the second is used to manage 32-bit data sources. 

If you are running a 32-bit Operating System, you will have only 32 bit drivers installed. If you are using a 64 bit machine, the default ODBC Manager will be for 64-bit data sources. 

 If you have a 64bit OS and are trying to access a DSN in your 32bit application and receive the error check to see if you have a DSN configured for the architecture of your application ( 32-bit / 64-bit ).

“ERROR [IM014] [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application” 

Use this ODBC Manager to Review 64-Bit Data Source Names 
c:\windows\system32\odbcad32.exe 

Use this ODBC Manager to Review 32-Bit Data Source Names c:\windows\sysWOW64\odbcad32.exe

Friday, October 10, 2014

Login History Server Trigger




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