title: WebSocket listener for Microsoft SQL Database
body: <p>I am currently working on a project which has to use WebSockets as a way of transferring data to my client. The infrastructure looks like this.<br />
  Client --> Web Server --> Microsoft SQL Database</p>
  
  <p>I think that the most ideal situation would be like this:
  Client opens a socket to the Server.
  Server opens a socket to the Microsoft SQL Database.
  Whenever the database is updated (some data has been inserted) the DB writes the data to the socket.
  The server writes the data back to the client.
  This might be a bit tedious though, maybe I can somehow open a socket to the DB from the client directly? </p>
  
  <p><strong>I want to know if there is a way to automatically notify the socket to the web server if the MSSQL database is updated, so that it can process that information.</strong></p>
  
  <p>The main question is really; how will I make this work? I've looked into some projects which work with WebSockets like Node.JS and Socket.IO, also Tornado. Although I haven't found any clues as to where to look for this specific feature. I have found some rather unstable drivers for the MSSQL databases for NodeJS but do not understand if there is any way to make a socket to the DB and instantly send the data through the socket when it's pumped into the database.</p>
  
  <p>I also realise that making a socket between client and db wouldn't be smart to say the least security wise, as for now that's not an issue, and that SQL is not the way to go for realtime applications but I'm bound to it for now :)</p>
  
  <p><strong>Edit 1:</strong></p>
  
  <p>Thanks to @tomfanning I now know of a solution to this problem but seriously doubt the improvement in performance. Let me picture the situation for you. In the case that I would use the Trigger on the MSSQL database I imagine this happening.</p>
  
  <p><strong>Situation 1</strong></p>
  
  <ol>
  <li><em>The database gets updated</em>    </li>
  <li><em>The trigger is pulled</em>  </li>
  <li><em>The CLR script makes a connection to the Web Server. Either through
  a socket which it has to open and close for every trigger or through
  a HTTP(S) request which involves opening and closing a Header (which
  is useless overhead)</em>   </li>
  <li><em>The Web Server receives the trigger and emits the data to the
  client.</em>  </li>
  <li><em>The client updates.</em></li>
  </ol>
  
  <p>And now imagine the same scenario but then with AJAX</p>
  
  <p><strong>Situation 2:</strong></p>
  
  <ol>
  <li><em>A timeout of 1000ms is set in the client for AJAX requests</em></li>
  <li><em>The client time's out and makes an AJAX request</em></li>
  <li><em>The database executes some query and posts back the result</em></li>
  <li><em>The client updates.</em></li>
  </ol>
  
  <p>In situation 1 you need both a request and a socket emit/receive and in situation 2 you would only need one request. If I were to set the timeout of the AJAX request to 10MS would it appear to the user as if it were a realtime application like a websocket? Or would situation 1 still be more efficient and I'm just exaggerating?</p>
  
  <p>Thanks in advance!</p>