Data Connection with Java Script


#1

I am attempting to make a data connection using Javascript and have developed code as below:

function CheckLotNo2() {

  var objConnection = new ActiveXObject("adodb.connection");
  var strConn = "driver={sql server}; server=localhost; database=test4; username= ; password=root ";
  **_Connection.Open(strConn);_**
  var rs = new ActiveXObject("adodb.Recordset");
  rs.Open("SELECT fname, lname, address, phone, email FROM  Customer1 where trim lotno = '400' ", connection);
  
  var vlotno = ($row["lotno"]);
  var vFname = ($row["fname"]);
  var vLname = ($row["lname"]);
  var vAddress = ($row["address1"]);
  var vPhone = ($row["phone1"]);
  var vEmail = ($row["email"]);

  document.getElementById("lotno").value = vlotno;
  document.getElementById("fname").value = vFname;
  document.getElementById("lname").value = vLname;
  document.getElementById("address").value = vAddress;
  document.getElementById("phone").value = vPhone;
  document.getElementById("email").value = vEmail;

  }

I am getting an error message for the line above in bold.

I am trying to do a lookup on a lotno and populate the screen with fname, lname etc. which is available in the Customer1 sql data file.

Any help would be appreciated.

Mike


#2

Is that supposed to be
username= ;
and not
username=''; (empty string)
or a string value other than empty?
Should the other values be inside quotation marks?


#3

Also, the thing you’ve copied has put quote marks in curly form in most of your post, but not in these two lines:
var strConn = "driver={sql server}; server=localhost; database=test4; username= ; password=root ";
rs.Open("SELECT fname, lname, address, phone, email FROM Customer1 where trim lotno = ‘400’ ", connection);

You might want to make sure that these quote marks are the same as all other ones in your script.
what error message are you getting from the script? First impulse? Connection is not an object you have defined. You’ve defined something called objConnection, but not something called Connection.


#4

Is ActiveXObject even a possibility these days? I was under the impression that browsers stopped supporting it quite some time ago. Though perhaps it will still work in some cases?


#5

The error would be falling out of that line with the error message “ActiveXObject is not defined” if that were the case. The fact that the javascript gets as far as it does says their browser recognizes some object definition for the class ActiveXObject


#6
function CheckLotNo2() {
  var Connection = new ActiveXObject("adodb.connection");
  var strConn = "driver={sql server}; server='localhost'; database='test4'; username= ' ' ; password='root' ";
  Connection.Open(strConn);
  var rs = new ActiveXObject("adodb.Recordset");
  rs.Open("SELECT fname, lname, address, phone, email FROM  Customer1 where trim lotno = '400' ", connection);
  
  var vlotno = ($row["lotno"]);
  var vFname = ($row["fname"]);
  var vLname = ($row["lname"]);
  var vAddress = ($row["address1"]);
  var vPhone = ($row["phone1"]);
  var vEmail = ($row["email"]);

  document.getElementById("lotno").value = vlotno;
  document.getElementById("fname").value = vFname;
  document.getElementById("lname").value = vLname;
  document.getElementById("address").value = vAddress;
  document.getElementById("phone").value = vPhone;
  document.getElementById("email").value = vEmail;

  }
</script>

I have put in single quotes around the parameters for the data connection as above.

Now when I try this it I get the following:

  • first it puts up 2 messages about whether this is a trusted web site
  • if I ignore those 2 messages then it puts up a message about
    [Microsoft]ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist.

I investigated this and Microsoft acknowledges a problem with some browsers and offers a work around which looks complicated.
Is there some way of using Javascript to connect to a SQL Table without using ActiveXObject?

Mike


#7

What I could find did look complicated. I got the impression current documention was for Edge and maybe IE working with IIS / Windows OS specifically. If this is the case, because there are “cloud” services I think developing in this direction is a possibility. But it isn’t anything I have done.

Is this a new project or an existing one you want to work with?

I ask because if your goal is to have JavaScript work with a users database, there are options. SQLite and IndexedDB come to mind. As for working with a remote database, I think the best approach would be a serverside script and not use JavaScript except for XHR to work with the API


#8

I am working on a new project where the sql data files will reside on the GoDaddy web site.

I am doing development work on my localhost right now.

I have a screen for ordering restaurant menu items from the web site. I have a few onclick() functions built into the ordering screen to calculate totals etc. .

At the top of this screen there is a place to enter your lot no. After they enter their lot no, I want to use onmouseup() to go to the customer file and get the fname, lname, phone etc. and populate the restaurant ordering screen.

Is it possible to integrate server side code into this type of screen?

I am not wedded to a specific approach?

Mike


#9

Assuming your GoDaddy host is a typical Apache, MySQL and PHP site, and your localhost is also Apache, MySQL and PHP you should have few if any problems.

The most complicated step will most likely be coming up with a good database design. After that is done it’s only a matter of writing the server-side script to work with the database and client-side pages to do HTTP Requests to the server-side script(s).

Do you have your table schema(s) worked out already?


#10

I have not used schemas to build my tables.

I have 3 tables:

  • one is for storing the restaurant orders
  • one is for storing the profiles of the customers
  • one is for reservations for events, it keeps track of the events and the people who have booked in to each event

This part is simple and straight forward. I worked for years with a language called Visual Foxpro so tables and code are similar in most cases. I am using Microsoft Report Builder for the Reports and it seems to work pretty well.

I will look into SQLite and see if I can get that working.

Mike