<i id='lu4qK'><tr id='lu4qK'><dt id='lu4qK'><q id='lu4qK'><span id='lu4qK'><b id='lu4qK'><form id='lu4qK'><ins id='lu4qK'></ins><ul id='lu4qK'></ul><sub id='lu4qK'></sub></form><legend id='lu4qK'></legend><bdo id='lu4qK'><pre id='lu4qK'><center id='lu4qK'></center></pre></bdo></b><th id='lu4qK'></th></span></q></dt></tr></i><div id='lu4qK'><tfoot id='lu4qK'></tfoot><dl id='lu4qK'><fieldset id='lu4qK'></fieldset></dl></div>

  1. <tfoot id='lu4qK'></tfoot>

    <legend id='lu4qK'><style id='lu4qK'><dir id='lu4qK'><q id='lu4qK'></q></dir></style></legend>
      <bdo id='lu4qK'></bdo><ul id='lu4qK'></ul>

    <small id='lu4qK'></small><noframes id='lu4qK'>

    1. 如何在浏览器中从 JavaScript 连接到 SQL Server 数据库?

      时间:2023-07-17

        <tfoot id='aLeGr'></tfoot>

          <i id='aLeGr'><tr id='aLeGr'><dt id='aLeGr'><q id='aLeGr'><span id='aLeGr'><b id='aLeGr'><form id='aLeGr'><ins id='aLeGr'></ins><ul id='aLeGr'></ul><sub id='aLeGr'></sub></form><legend id='aLeGr'></legend><bdo id='aLeGr'><pre id='aLeGr'><center id='aLeGr'></center></pre></bdo></b><th id='aLeGr'></th></span></q></dt></tr></i><div id='aLeGr'><tfoot id='aLeGr'></tfoot><dl id='aLeGr'><fieldset id='aLeGr'></fieldset></dl></div>

          <small id='aLeGr'></small><noframes id='aLeGr'>

              <bdo id='aLeGr'></bdo><ul id='aLeGr'></ul>
                  <tbody id='aLeGr'></tbody>

                <legend id='aLeGr'><style id='aLeGr'><dir id='aLeGr'><q id='aLeGr'></q></dir></style></legend>
              1. 本文介绍了如何在浏览器中从 JavaScript 连接到 SQL Server 数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                谁能给我一些示例源代码,展示如何从本地 JavaScript 连接到 SQL Server 2005 数据库?我正在台式机上学习网络编程.

                Can anybody give me some sample source code showing how to connect to a SQL Server 2005 database from JavaScript locally? I am learning web programming on my desktop.

                或者我需要使用任何其他脚本语言吗?如果你有的话,建议一些替代方案,但我现在正在尝试用 JavaScript 来做.我的 SQL Server 本地安装在我的桌面上——SQL Server Management Studio 2005 和 IE7 浏览器.

                Or do I need to use any other scripting language? Suggest some alternatives if you have them, but I am now trying to do it with JavaScript. My SQL Server is locally installed on my desktop — SQL Server Management Studio 2005 and IE7 browser.

                推荐答案

                出于多种原因(不良做法、安全问题等),您不应该使用客户端 javascript 访问数据库,但如果您真的想这样做,这里是一个例子:

                You shouldnt use client javascript to access databases for several reasons (bad practice, security issues, etc) but if you really want to do this, here is an example:

                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; 
                

                连接到 sql 服务器的更好方法是使用一些服务器端语言,如 PHP、Java、.NET 等.客户端 javascript 应仅用于接口.

                A better way to connect to a sql server would be to use some server side language like PHP, Java, .NET, among others. Client javascript should be used only for the interfaces.

                并且有关于服务器javascript存在的古老传说的传言,但这是另一回事.;)

                And there are rumors of an ancient legend about the existence of server javascript, but this is another story. ;)

                这篇关于如何在浏览器中从 JavaScript 连接到 SQL Server 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:暂时关闭约束 (MS SQL) 下一篇:使用 merge..output 获取 source.id 和 target.id 之间的映射

                相关文章

                    <legend id='JdfyW'><style id='JdfyW'><dir id='JdfyW'><q id='JdfyW'></q></dir></style></legend>
                    • <bdo id='JdfyW'></bdo><ul id='JdfyW'></ul>

                  1. <i id='JdfyW'><tr id='JdfyW'><dt id='JdfyW'><q id='JdfyW'><span id='JdfyW'><b id='JdfyW'><form id='JdfyW'><ins id='JdfyW'></ins><ul id='JdfyW'></ul><sub id='JdfyW'></sub></form><legend id='JdfyW'></legend><bdo id='JdfyW'><pre id='JdfyW'><center id='JdfyW'></center></pre></bdo></b><th id='JdfyW'></th></span></q></dt></tr></i><div id='JdfyW'><tfoot id='JdfyW'></tfoot><dl id='JdfyW'><fieldset id='JdfyW'></fieldset></dl></div>
                  2. <small id='JdfyW'></small><noframes id='JdfyW'>

                    <tfoot id='JdfyW'></tfoot>