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: 
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 :)
No, you can't call a javascript function on the **client** from a web service on a **server**.