Wrong connection string to a sql-server

A

Andy Wawa

Hi,
on a simple HTML (not an ASP!)-Site I try to connect to a sql server
(MS):

<html>
<title>Test</title>
<head>
<script language="javascript">
<!--
Function showForm(){
var conn
conn = CreateObject("ADODB.Connection");
var rst
var = CreateObject("ADODB.recordset");
var sql
sql = "select f01, f02 from IT_ASP where id < 10";
conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=Projekt;Data Source=MYSERVER\MYSQL;pwd=123Abc.";
rst.Open (sql, conn);
while (!rst.EOF){
document.write(rst(0));
document.write("<br>");
rst.MoveNext;
}
rst.Close;
rst=Nothing;
document.close;
}
//-->
</script>
</head>
<body>
<form name="myform" action="">
<input name="but1" type="button" value="klick"
onClick="javascript:showForm()">
</form>
</body>
</html>

I'm still getting an error: object expected.
What's wrong? (I know, it's late...)
Andy
 
H

Hywel Jenkins

Hi,
on a simple HTML (not an ASP!)-Site I try to connect to a sql server
(MS):

I'm still getting an error: object expected.
What's wrong? (I know, it's late...)

And you seem to be trying to run ASP code on the client. How do figure
that will work?
 
R

Richard Cornford

Andy Wawa said:
on a simple HTML (not an ASP!)-Site I try to connect to
a sql server (MS):

<html>
<title>Test</title>
<head>
<script language="javascript">
<!--
Function showForm(){
var conn
conn = CreateObject("ADODB.Connection");

I think that CreateObject is VBScript not JavaScript.

conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=Projekt;Data Source=MYSERVER\MYSQL;pwd=123Abc.";
<snip>

If this is Internet I hope you have thought out the security
implications of sending this information to the client.

Richard.
 
S

Stephen

Andy said:
Hi,
on a simple HTML (not an ASP!)-Site I try to connect to a sql server
(MS):

Do you want this to run server-side or client-side?

I believe you're mixing VBScript with JavaScript/JScript...

Plus, there's lots more than the connection string to worry about...
<html>
<title>Test</title>
<head>
<script language="javascript">

We'd probably prefer to write

<script type="text/javascript">

but that's not related to your problem...
<!--
Function showForm(){

JavaScript is case sensitive, and this should be

function showForm() {

var conn
conn = CreateObject("ADODB.Connection");

Should be, I believe:
conn = new ActiveXObject("ADODB.Connection");

var rst
var = CreateObject("ADODB.recordset");
var sql

Should be, maybe rst= new ActiveXObject(...etc...)?
instead of var=CreateObject(...etc...)

Note, on these 2 lines, we're expecting a client-side database. You may
get security warnings or may die all together.


sql = "select f01, f02 from IT_ASP where id < 10";
conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=Projekt;Data Source=MYSERVER\MYSQL;pwd=123Abc.";

Looks like VB syntax above. In js put the connection string in ()'s.
conn.Open("...") --or--

var connectionString = " ... "
conn.Open(connectionString);
rst.Open (sql, conn);
while (!rst.EOF){
document.write(rst(0));

I suspect a problem with the above line. What, really, is rst(0)? Is it
a record? The write() method takes string arguments or converts the
argument to string before writing.

Actually you maybe need rst.Fields(0) or something like that for the
field you want. Else you may have data type problems.
document.write("<br>");
rst.MoveNext;

above s/b rst.MoveNext();
}
rst.Close;

above s/b rst.Close();
rst=Nothing;

The above line is VB, not javascript. Delete it.
document.close;

I think this also is document.close();

It's a *method*, which is a function, so you need the function operator ()
}
//-->
</script>
</head>
<body>
<form name="myform" action="">
<input name="but1" type="button" value="klick"
onClick="javascript:showForm()">

In the above, lose the "javascript:". It's just

onClick="showForm()"
</form>
</body>
</html>


Other points ...
Figuring out what the connection string is one of the hardest things
about ADO for me. I don't know if that's correct for your case or not.

This coding assumes that the database is on the client, not server. If
the database is on the server, use ASP.

I know with, say, a VB program you could connect to a database across
the 'net via ADO. I don't know if you'll run into security problems or
not trying to do that from within a web page. My guess is probably so.
I'm still getting an error: object expected.
What's wrong? (I know, it's late...)
Andy

Lots of debugging to do. Make sure you use *javascript* syntax
throughout. Dont confuse with VBScript. Or give up on js and *just* use
VBScript.

Don't know that I found everything, but this is a start, at least....

Stephen
 
L

Laurent Bugnion, GalaSoft

Hi Richard,

Richard said:
I think that CreateObject is VBScript not JavaScript.

Actually, CreateObject as such is part of ASP, and can be used in
VBScript, JScript or any language supported by ASP. It's just an API method.

On ASP (server-side), it's perfectly legal to use CreateObject to
instantiate COM components. That's the beauty (IMHO) of ASP, and now of
..NET: The platform expose a set of objects which can be used with the
same signature in any supported language. This allows you to choose
whichever language you prefer without losing the efficiency of the platform.

Laurent
 
A

Andy Wawa

Hi,
I really mixed VBScript and JavaScript! Unfortunately I have to script
it on the client-side, so an ASP-Solution can't be used (I only have
access at this one special SQL-Server table and nothing more)...
The proper script looks like that:

<SCRIPT type="text/javascript">
<!--
function Aufruf(){
var rst;
var dsn;
var sql;
var newWindow;
rst = new ActiveXObject("ADODB.Recordset");
dsn = new ActiveXObject("ADODB.Connection");
dsn.Open ("Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=myID;Initial Catalog=Projekt;Data Source=MyServer;pwd=mypass");
sql = ("select gpar_name1, gpar_name2 from adress");
rst.Open (sql, dsn);
newWindow = window.open("","","width=600, height=400,top=200
left=200,scrollbars");
while (!rst.EOF){
newWindow.document.write(rst(0) + " " + rst (1));
newWindow.document.write("<br>");
rst.moveNext();
}
rst.Close();
}

Thanks for your help, advices and tips :))
Andy
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top