Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to connect sqlserver database in javascript.
if u know the creating the database connection,please share the information
Posted

Please try this....

JavaScript
var connection = new ActiveXObject("ADODB.Connection") ;

var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";

connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");

rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
{
   document.write(rs.fields(1));
   rs.movenext;
}

rs.close;
connection.close;


Regards
Sebastian
 
Share this answer
 
v2
connecting sqlserver database in javascript is not a good idea , and ActiveXObject will only work in IE.You should try creating a wcf service and call that service from your javascript code, or create an asp.net handler(ashx) , in both cases your response should be in JSON or XML. There is also a third approach if you want to call the server function in Javascript use SignalR. There is a topic in SignalR about calling server side function in Javascript.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900