title: Blocking IP Addresses from logging into SQL Server
body: <p>We have an SQL Server database which is getting bombarded each day with login attempts.  It is on an online server and I am sure you'll frown upon the fact that it is accessible to the outside world but I cannot do much about that (but am open to suggestions)..  I have found a way by searching online to restrict log ins by IP address in the following code..  I like the idea of this code running but I want to only run the check if the log in is unsuccessful..  does anyone know what is returned if unsuccessful?</p>
  
  <p>Many thanks,</p>
  
  <p>Derek</p>
  
  <pre><code>-- -- Block IP Addresses to SQL Server using a Logon Trigger -- 
  CREATE TRIGGER LogonTrigger_RestrictIpAddresses     
  ON ALL SERVER     
  FOR LOGON AS
  BEGIN    
  DECLARE @IP Varchar( 500 )     
  SET @IP = EVENTDATA().value( '(/EVENT_INSTANCE/ClientHost)[1]', 'varchar(500)' )           
  -- set of the restricted IP addresses     
  IF @IP IN ( '172.16.255.11', '172.20.254.1', '172.26.254.12' )     
  BEGIN        
  Print 'Logging in from the restricted IP: ' + @IP         
  ROLLBACK TRANSACTION    
  END
  END
  GO
  </code></pre>