Click here to Skip to main content
15,885,954 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
JavaScript
function data() {
    var connection = new ActiveXObject("ADODB.Connection");

    var connectionstring = "Data Source=elabsqldb2.db.11460868.hostedresource.com;Initial Catalog=elabsqldb2;User ID=elabsqldb2;password=elab17TRACK#14";
    connection.Open(connectionstring);
    var rs = new ActiveXObject("ADODB.Recordset");

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

    rs.close;
    connection.close;

}



Am not able to read a output .
Posted
Updated 20-Oct-21 9:10am
v2
Comments
Member 12119075 6-Jan-16 2:33am    
<script type="text/javascript" src="Myscript.js">
</script>

Am trying to call this method from aspx button
[<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" OnClientClick="data()" />]
Kornfeld Eliyahu Peter 6-Jan-16 2:41am    
It is very bad idea to use ActiveX...Why it is so important to you to directly access the database from the client and not to put a layer on the server between the two?
Member 12119075 6-Jan-16 2:51am    
i refered this link to achieve and my lead also asking me to follow this model

http://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript-in-the-browser
Kornfeld Eliyahu Peter 6-Jan-16 2:56am    
It is a discussion from 2009! World changed since and ActiveX became an ancient, not supported technology...
I would advise you too look further...
1. It works only on older IE (no Chrome or Firefox or IE11 (9-10 too has its problem)
2. It is very dependent on the permissions the local user have
3. It is extremely non-flexibile
Member 12119075 6-Jan-16 3:01am    
thank u very much , how do i pass data from server side to Clint side script ? give me a suggestion

1 solution

Using nodejs and mysql you can achieve it.

C#
var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : '< MySQL username >',
  password : '< MySQL password >',
  database : '<your database name>'
});

connection.connect();

connection.query('SELECT * from < table name >', function(err, rows, fields) {
  if (!err)
    console.log('The solution is: ', rows);
  else
    console.log('Error while performing Query.');
});

connection.end();
 
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