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 can "call" javascript directly from the webservice... Or more correctly spoken you can use a publish/subscribe pattern to publish a message from you webservice and subscribe to it in your javascript.

Like @Daniel says we (XSockets) have called javascript from a compiled stored procedure, but that was a few years ago... I think it will be easier for you to take the approach where you "call" the javascript from a webservice.

To do it between webservice and javascript could be something like this...
JAVASCRIPT

```
//Setup a subscription for the event 'foo'
conn.on('foo', function(data){
    console.log('foo - some data arrived from the webservice', data);
});

```

C# (or VB if you want to)

```
//Connect to the realtime server and the default controller generic
var conn = ClientPool.GetInstance("ws://127.0.0.1:4502/Generic", "*");
//We send an anonymous message here, but any object will work.
conn.Send(new { Message = "Hello JavaScript from C#" },"foo");

```

Full example [here](http://xsockets.net/api/guides/boosting-a-wcf-to-realtime)

There may be some easier way to do this as well... if I knew a little bit more about what you are doing :)