如何在javascript中连接sqlserver数据库.如果您知道创建数据库连接,请共享信息 [英] How to connect sqlserver databse in javascript. if u know the creating the database connection,please share the information

查看:422
本文介绍了如何在javascript中连接sqlserver数据库.如果您知道创建数据库连接,请共享信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在javascript中连接sqlserver数据库.
如果您知道创建数据库连接的信息,请共享信息.

How to connect sqlserver database in javascript.
if u know the creating the database connection,please share the information

推荐答案

请尝试一下....

Please try this....

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;



问候
Sebastian



Regards
Sebastian


在javascript中连接sqlserver数据库不是一个好主意,并且ActiveXObject仅在IE中有效.您应该尝试创建wcf服务,并从javascript代码中调用该服务,或者创建一个asp.net handler(ashx),在两种情况下,您的响应都应为JSON或XML.如果要使用Javascript使用SignalR调用服务器功能,则还有第三种方法. SignalR中有一个主题涉及使用Javascript调用服务器端函数.
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.


这篇关于如何在javascript中连接sqlserver数据库.如果您知道创建数据库连接,请共享信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆