javascript中的数据库连接 [英] database connectivity in javascript

查看:56
本文介绍了javascript中的数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

var connectionstring="Data Source=NODE5/SQLSERVER2005;Initial Catalog=MDM;User ID=sa;Password=*******;Provider=SQLOLEDB";

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

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

rs.close;
connection.close;



=========================== ================================================== ========

i hav为数据库连接编写了这段代码,但它无法正常工作。

它给出了未定义activexobject的错误。

请告诉我哪里出错或者还有其他方法可以做到这一点..


=====================================================================================
i hav written this code for database connectivity but it is not working.
it is giving error that activexobject is not defined.
pls tell me where m going wrong or is there any other way to do this..

推荐答案

嗯,不是这样的!

你真的想给客户端提供SA密码吗?

从理论上讲,你可以直接从网络浏览器连接到数据库服务器,但这种方式是:

- 依赖浏览器

- 仅在同一网络上工作

- clinet需要安装sql驱动程序

- 安全废话

您应该在服务器端实现支持Web的中间轮胎,即执行身份验证和授权,并且至少执行DAL或BL。最好的方法是制作RESTful服务,如下所述:使用JSON的WCF REST服务 [ ^ ]
Well, not this way!
You really want to give the SA password to the client?
Theoretically you could connect directly from the web browser to a database server, but this way is:
- browser dependent
- working only on the same network
- the clinet needs sql driver installed
- security nonsense
You should implement a web-enabled mid-tire on server side, that is performing authentication and authorization and does at least DAL or BL. The best approach is making a RESTful service, like described here: WCF REST Service with JSON[^]


ActiveXObject是非标准的,只有Windows上的Internet Explorer支持。

但是可以使用html5将数据库与java脚本连接。

通过以下链接: -

介绍Web SQL数据库 [ ^ ]



祝你好运。
ActiveXObject is non-standard and only supported by Internet Explorer on Windows.
But it is possible to connect database with java script using html5.
Go through this link :-
Introducing Web SQL Databases[^]

Good luck.


这篇关于javascript中的数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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