Question: I have a situation where I have to call a a javascript method from SQL Server. I haven't found any solution to do the same. I found one thing that I can call web service from SQL Server but now the problem is "Can we call javascript function from web service (like we can do in code behind file of aspx page)"?

Please help

Answer: 
Well, it depends on what you mean. If I'm not mistaken the guys behind the free real-time communication platform, [xSockets](http://www.xsockets.net) have been able to use a compiled stored procedure in SQL Server to use xSockets to dispatch a call to connected clients (e.g using WebSockets). **I'm not saying this is something you should do**, I'm saying "I think they have done it". You will find contact info on their page or just tweet with #xsockets hash on Twitter and they will respond.
You could do this using [Server-Sent Events](http://www.w3.org/TR/eventsource/), which are supported in most recent browsers.

The PHP:

```
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');

echo "id: " . time() . " " . PHP_EOL;
echo "data: $message" . PHP_EOL;
echo PHP_EOL;
ob_flush();
flush();

```

The JS:

```
var source = new EventSource('/php');
source.onmessage = function(e) {
    console.log(e.data);
};

```