Wrong connection string to a sql-server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy Wawa

    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="javas cript">
    <!--
    Function showForm(){
    var conn
    conn = CreateObject("A DODB.Connection ");
    var rst
    var = CreateObject("A DODB.recordset" );
    var sql
    sql = "select f01, f02 from IT_ASP where id < 10";
    conn.Open "Provider=SQLOL EDB.1;Persist Security Info=False;User
    ID=sa;Initial Catalog=Projekt ;Data Source=MYSERVER \MYSQL;pwd=123A bc.";
    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="javasc ript: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!
  • Hywel Jenkins

    #2
    Re: Wrong connection string to a sql-server

    In article <3f6f6f06$0$620 76$75868355@new s.frii.net>,
    awrzaszczyk@arc or.de says...[color=blue]
    >
    > Hi,
    > on a simple HTML (not an ASP!)-Site I try to connect to a sql server
    > (MS):
    >[/color]
    Should
    Function showForm(){
    be
    function showForm(){


    --
    Hywel I do not eat quiche


    Comment

    • Hywel Jenkins

      #3
      Re: Wrong connection string to a sql-server

      In article <3f6f6f06$0$620 76$75868355@new s.frii.net>,
      awrzaszczyk@arc or.de says...[color=blue]
      >
      > 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...)[/color]

      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


      Comment

      • Richard Cornford

        #4
        Re: Wrong connection string to a sql-server

        "Andy Wawa" <awrzaszczyk@ar cor.de> wrote in message
        news:3f6f6f06$0 $62076$75868355 @news.frii.net. ..[color=blue]
        >on a simple HTML (not an ASP!)-Site I try to connect to
        >a sql server (MS):
        >
        > <html>
        > <title>Test</title>
        > <head>
        > <script language="javas cript">
        > <!--
        > Function showForm(){
        > var conn
        > conn = CreateObject("A DODB.Connection ");[/color]

        I think that CreateObject is VBScript not JavaScript.

        <snip>[color=blue]
        >conn.Open "Provider=SQLOL EDB.1;Persist Security Info=False;User
        >ID=sa;Initia l Catalog=Projekt ;Data Source=MYSERVER \MYSQL;pwd=123A bc.";[/color]
        <snip>

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

        Richard.


        Comment

        • Stephen

          #5
          Re: Wrong connection string to a sql-server

          Andy Wawa wrote:
          [color=blue]
          > Hi,
          > on a simple HTML (not an ASP!)-Site I try to connect to a sql server
          > (MS):
          >[/color]

          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...
          [color=blue]
          > <html>
          > <title>Test</title>
          > <head>
          > <script language="javas cript">[/color]

          We'd probably prefer to write

          <script type="text/javascript">

          but that's not related to your problem...
          [color=blue]
          > <!--
          > Function showForm(){[/color]

          JavaScript is case sensitive, and this should be

          function showForm() {

          [color=blue]
          > var conn
          > conn = CreateObject("A DODB.Connection ");[/color]

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

          [color=blue]
          > var rst
          > var = CreateObject("A DODB.recordset" );
          > var sql[/color]

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

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


          [color=blue]
          > sql = "select f01, f02 from IT_ASP where id < 10";
          > conn.Open "Provider=SQLOL EDB.1;Persist Security Info=False;User
          > ID=sa;Initial Catalog=Projekt ;Data Source=MYSERVER \MYSQL;pwd=123A bc.";[/color]

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

          var connectionStrin g = " ... "
          conn.Open(conne ctionString);
          [color=blue]
          > rst.Open (sql, conn);
          > while (!rst.EOF){
          > document.write( rst(0));[/color]

          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.
          [color=blue]
          > document.write( "<br>");
          > rst.MoveNext;[/color]

          above s/b rst.MoveNext();
          [color=blue]
          > }
          > rst.Close;[/color]

          above s/b rst.Close();
          [color=blue]
          > rst=Nothing;[/color]

          The above line is VB, not javascript. Delete it.
          [color=blue]
          > document.close;[/color]

          I think this also is document.close( );

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

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

          onClick="showFo rm()"
          [color=blue]
          > </form>
          > </body>
          > </html>
          >[/color]


          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.
          [color=blue]
          > I'm still getting an error: object expected.
          > What's wrong? (I know, it's late...)
          > Andy
          >[/color]

          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

          Comment

          • Laurent Bugnion, GalaSoft

            #6
            Re: Wrong connection string to a sql-server

            Hi Richard,

            Richard Cornford wrote:[color=blue]
            > "Andy Wawa" <awrzaszczyk@ar cor.de> wrote in message
            > news:3f6f6f06$0 $62076$75868355 @news.frii.net. ..
            >[color=green]
            >><script language="javas cript">
            >><!--
            >>Function showForm(){
            >>var conn
            >>conn = CreateObject("A DODB.Connection ");[/color]
            >
            >
            > I think that CreateObject is VBScript not JavaScript.[/color]

            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

            Comment

            • Andy Wawa

              #7
              Re: Wrong connection string to a sql-server

              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.Connectio n");
              dsn.Open ("Provider=SQLO LEDB.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=6 00, height=400,top= 200
              left=200,scroll bars");
              while (!rst.EOF){
              newWindow.docum ent.write(rst(0 ) + " " + rst (1));
              newWindow.docum ent.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!

              Comment

              Working...