Home > Miscellaneous > Block IP Addresses in MS SQL Server

Block IP Addresses in MS SQL Server

In most cases when we make API calls from a web application hosted on a Server or a VM. We want to make sure that the database is secured and only accessible to a particular group of individuals. In this case we can allow or block particular IP addresses as situation may demand.

 

There is no direct method where an IP address can be blocked or allowed to a particular MS SQL database, But the trick is to write a command language trigger on logon event to suffice the need.

 

For this we need to maintain the list of IP addresses that need to be blocked or allowed on the database (we shall look at blocked example). We can create a table on the master database with the IP address list as follows

 

The following trigger will help in blocking the request coming from the listed IP addresses
 

 

 
The above trigger will prevent login request that are generated from the listed IP addresses.
 
Post comments if this helps.
 
This Article is TAGGED in , , , . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">