472,108 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,108 software developers and data experts.

Wrong connection string to a sql-server


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
6 23418
In article <3f***********************@news.frii.net>,
aw*********@arcor.de says...

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

Should
Function showForm(){
be
function showForm(){
--
Hywel I do not eat quiche
http://hyweljenkins.co.uk/
http://hyweljenkins.co.uk/mfaq.php
Jul 20 '05 #2
In article <3f***********************@news.frii.net>,
aw*********@arcor.de says...

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?

--
Hywel I do not eat quiche
http://hyweljenkins.co.uk/
http://hyweljenkins.co.uk/mfaq.php
Jul 20 '05 #3
"Andy Wawa" <aw*********@arcor.de> wrote in message
news:3f***********************@news.frii.net...
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.

<snip>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.
Jul 20 '05 #4
Andy Wawa wrote:
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

Jul 20 '05 #5
Hi Richard,

Richard Cornford wrote:
"Andy Wawa" <aw*********@arcor.de> wrote in message
news:3f***********************@news.frii.net...
<script language="javascript">
<!--
Function showForm(){
var conn
conn = CreateObject("ADODB.Connection");

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
--
Laurent Bugnion, GalaSoft
Webdesign, Java, javascript: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch

Jul 20 '05 #6
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mike Moore | last post: by
3 posts views Thread by Andrew Johnson | last post: by
7 posts views Thread by greg | last post: by
6 posts views Thread by Backwards | last post: by
9 posts views Thread by rcoco | last post: by
reply views Thread by Robert Avery | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.