473,384 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,384 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 23493
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Moore | last post by:
We are developing an asp.net web application. When we drag and drop the sql connection object to the form we set the in the dynamic properties connection string to use the connection string in the...
3
by: Andrew Johnson | last post by:
Hi, I am trying to make a UBD DB2 7.2 connection using the Java COM.ibm.db2.jdbc.app.DB2Driver via Tomcat 3.2.1 on Solaris (and also on an AIX system with 3.3.1). I am attempting this either...
2
by: Ken | last post by:
How can I copy data from SQL to MS Access using dsn-less connection and not using SQL DTS? I have this but am stuck. I just want to do an export but can't figure out how to do a "select into". ...
2
by: Jim | last post by:
Is it possible to have a Connection class that opens up connection to my DB and leaves it open until I decide to close it? I run many SQL statements so I was wondering if it's possible to call a...
3
by: Wing | last post by:
Hi all, I am writing the C# code function that take 2 parameters and access the data in the MS SQL database and return a SqlDataReader object. In my funtion, a SQL connection is established and...
7
by: greg | last post by:
Hi We have w2k, iis5, .NET/c# I periodically receive this message and the system freezes ++++++++++++++++++++++++++++++++++++++++++++++++++ Timeout expired. The timeout period elapsed...
6
by: Backwards | last post by:
I'm using visual studio 2005 and SQL 2000, trying to connect to a sql database as a differnent user. Here is my current connection string that is using my own NT login: Dim message As String =...
0
by: Arielle | last post by:
Please tell me what's wrong with this picture. public class MyClass { SqlConnection ConnectionSql = null; SqlCommand CommandSql = null; SqlDataReader QueryResult = null;
9
by: rcoco | last post by:
Hi, I'm just wondering if I'm on the write truck. this code is ment to look for an ID number in the datagrid that matches the the ID number that is in the textbox I created. But it's not...
0
by: Robert Avery | last post by:
In VBA/VB6, I had a class (incomplete sample below) that watched and displayed for the user all connection events, so that I could easily see what SQL was taking a long time, and when it freezes, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.