Wrong connection string to a sql-server

Discussion in 'Javascript' started by Andy Wawa, Sep 22, 2003.

  1. Andy Wawa

    Andy Wawa Guest

    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!
     
    Andy Wawa, Sep 22, 2003
    #1
    1. Advertising

  2. Hywel Jenkins, Sep 22, 2003
    #2
    1. Advertising

  3. In article <3f6f6f06$0$62076$>,
    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
     
    Hywel Jenkins, Sep 22, 2003
    #3
  4. "Andy Wawa" <> wrote in message
    news:3f6f6f06$0$62076$...
    >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.
     
    Richard Cornford, Sep 23, 2003
    #4
  5. Andy Wawa

    Stephen Guest

    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
     
    Stephen, Sep 23, 2003
    #5
  6. Hi Richard,

    Richard Cornford wrote:
    > "Andy Wawa" <> wrote in message
    > news:3f6f6f06$0$62076$...
    >
    >><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
     
    Laurent Bugnion, GalaSoft, Sep 23, 2003
    #6
  7. Andy Wawa

    Andy Wawa Guest

    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!
     
    Andy Wawa, Sep 23, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vighnesh
    Replies:
    1
    Views:
    5,556
    Landley
    Sep 29, 2005
  2. Joey
    Replies:
    3
    Views:
    4,430
  3. OJ
    Replies:
    5
    Views:
    1,426
    Juan T. Llibre
    May 14, 2007
  4. Brett
    Replies:
    8
    Views:
    914
    sloan
    Jul 30, 2008
  5. John Kennedy
    Replies:
    5
    Views:
    231
    Carl Prothman [MVP]
    Aug 14, 2003
Loading...

Share This Page