How can Connection ODBC Driver by Client JavaScript

J

Jack

Hello,
I wrote this code:
<%@ LANGUAGE=VBScript %>
<SCRIPT LANGUAGE=JavaScript>
function CustomerNameChange()
{
var forwarding_dbX;
var CustomerTableX;
set forwarding_dbX = Server.CreateObject("ADODB.Connection");
forwarding_dbX.Open "Forwarding";
set CustomerTableX= forwarding_dbX.Execute("SELECT * FROM CustomerTable
WHERE CustomerName='"&CustomerName.value&"'");
text153.value=CustomerTableX.Fields("Abbreviation")
}
</SCRIPT>
<%
Dim forwarding_db
Set forwarding_db = Server.CreateObject("ADODB.Connection")
forwarding_db.Open "Forwarding"
Dim ForwardingTable
Dim CustomerTable
Set ForwardingTable = forwarding_db.Execute("SELECT * FROM Forwarding WHERE
ID =" & Request.QueryString("ID"))
Set CustomerTable= forwarding_db.Execute("SELECT * FROM Customer")
Response.Write "<SELECT id=CustomerName name=CustomerName
onchange=""CustomerNameChange()"">"
CustomerTable.Movefirst
Do until CustomerTable.EOF
Response.Write "<OPTION Value=" & CustomerTable.Fields("CustomerName")
if CustomerTable.Fields("CustomerName") =
ForwardingTable.Fields("CustomerName") then
Response.Write " Selected"
end if
Response.Write ">"
Response.Write CustomerTable.Fields("CustomerName")
Response.Write "</OPTION>"
CustomerTable.MoveNext
Loop
Response.Write "</SELECT>"
Response.Write "<INPUT type=""text"" id=text153 name=text153 >"
%>
But when change the CustomerName's SELECT,text153 can't shows
CustomerTableX.Fields("Abbreviation").I think in function
CustomerNameChange(),ODBC Driver not been connectioned.
Can you help me
 
A

Aaron Bertrand - MVP

set forwarding_dbX = Server.CreateObject("ADODB.Connection");

Sorry, this makes no sense. Client-side JavaScript cannot make an
ADODB.Connection to the server. You will need to submit to the server in
some way to make a new request from the database.
 
J

Jack

Thank you for you advice.

I corrected the function
I wrote this code:

var forwarding_dbX;
var CustomerTableX;
forwarding_dbX = new ActiveXObject("ADODB.Connection");
forwarding_dbX.open("Forwarding");

But the final line is not correct.
Can you help me
 
R

Ray at

Jack, you've been trying this for a couple of months now with mixing your
client side code and server-side code. How can we help you understand? The
server side code runs on the server and returns and html page to the
browser. When your page loads in a browser, do a view-source. Everything
that you see in that view-source is everything that the server does NOT see,
for all intents and purposes. It sees it, but it makes no attempt to do
anything with it other than to dump it off to the client machine that
requested the text. It doesn't matter if it says <script>function
whatever()</script>. If you see it in a view-source, to the server, it is
just a meaningless chunk of characters.

Now compare your view-source with your ASP source file. Everything that you
see in the source file that you do NOT see in your view-source is what the
server sees and actually processes and cares about.

Does this help at all or make any sense?


<SCRIPT LANGUAGE=JavaScript>
function CustomerNameChange()
{
var forwarding_dbX;
var CustomerTableX;
set forwarding_dbX = Server.CreateObject("ADODB.Connection");
forwarding_dbX.Open "Forwarding";
set CustomerTableX= forwarding_dbX.Execute("SELECT * FROM CustomerTable
WHERE CustomerName='"&CustomerName.value&"'");
text153.value=CustomerTableX.Fields("Abbreviation")
}
</SCRIPT>

That is only seen by the browser. The server-side code has no idea what
"CustomerNameChange" is. As far as the server is concerned, that chunk of
text could be:

kja akjs dlkja8fajlk jfa
adfjkajd98f ali fadjf
ajdfaodsijfiad
fakdjfkja fd
ds98j4i
fjaijf
adf


It doesn't mean anything to the server. The user's browser is what will
know that function and be able to do something with it.

Ray at home
 
B

Bob Barrows

Aaron said:
Sorry, this makes no sense. Client-side JavaScript cannot make an
ADODB.Connection to the server. You will need to submit to the
server in some way to make a new request from the database.

Actually, it can, if the user has the proper security, and the database is
accessible, such as would be the case in an intranet application. I've
tested it and it does work.

The more over-riding question is: should you do it this way? Using ADO code
in client-side script means you have to make sure:

1. A working installation of MDAC exists on all the client machines, which
is not always the case (voice of experience here).
2. The database has to be accessible from all the client machines, either
via a network, or via installing the file-based database on the users'
machines <ugh!>
3. If you are using a DSN (definitely not recommended) or a UDL file (less
recommended, but at least it can use the native OLEDB provider for the
database), you will need to install the DSN or UDL file on all users'
machines.
4. The latest version of MDAC and IE include new security provisions to
prevent hacking. Some of these provisions will cause the user to receive
annoying warnings whenever the database is accessed
5. ... ummm - I've lost my train of thought (must be encroaching senility).
I had another point to make but it escapes me. I'm out of time anyways.

Bob Barrows
 
A

Aaron Bertrand [MVP]

Sorry, this makes no sense. Client-side JavaScript cannot make an
Actually, it can, if the user has the proper security, and the database is
accessible, such as would be the case in an intranet application.

All right, touche'... allow me to rephrase... Client-side JavaScript has no
business making an ADODB.Connection to the server. Better? :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top