
Reusing ADO connections in HTA applications
Thanks a lot ! So I was wrong about the scope of a variable ! I really think
this kind of feature is worth publishing; it would be nice to find something
about this when searching the MSDN library about variable scope.
Now, I would like to add this: in the mean time I went on trying my first
idea to use the object tag (just because I knew I could use the "parent"
syntax) and it worked. The problem is that the article on the ADO site is a
little bit misleading (http://ww.microsoft.com/data/ado/sams/ch08.htm):
- 1. the syntax to define an object is not correct : <OBJECT> NAME=cn
CLSID="CLSID:....." </OBJECT> should be .... CLASSID="CLSID...."
- 2. the Clsid itself is a little bit old : it's version 1.0 of
ADODB.connection; by using the new Clsid (just search the registery), I got
the thing working
Thanks again : I really learned something with your answer (by the way :
thanks for the answers you give to other questions too: it is always worth
reading).
John
Quote:
> === parent.hta ===
> <html>
> <head>
> <title>parent.hta</title>
> <hta:application id='myhta'>
> <script language='vbscript'>
> set cn = createobject("adodb.connection")
> </script>
> </head>
> <body>
> <iframe application='yes' src='child.htm'></iframe>
> </body>
> </html>
> === child.htm ===
> <html>
> <head>
> <title> child.htm in iframe </title>
> <script language='vbscript'>
> sub btn_onclick()
> set mycn = parent.cn
> msgbox "TypeName(mycn) = " & typename(mycn)
> end sub
> </script>
> </head>
> <body>
> <input type=button id="btn" value="Get cn from parent">
> </body>
> </html>
> --
> Michael Harris
> MVP Scripting
Quote:
> Of course, that would be fine. But please tell me more. How can I access
the
> global cn variable on the main HTA page from the sub-page ? I thought that
> the scope of a variable was limited to the page where it is declared; but
> perhaps I am wrong there ?
> Thanks a lot,
> John
> > Why not just create it with CreateObject, the same as you would in
server
> side ASP code?
> > set cn = CreateObject("ADODB.Connection")
> > where cn is a global variable in the main HTA page...
> > --
> > Michael Harris
> > MVP Scripting
> > Hi,
> > I am currently busy writing an HTA application (windows NT with IE5
> > installed). I have a main screen with an IFRAME on it. The user can
choose
> > what he wants to see in this IFRAME. In the main window and also some of
> the
> > sub-windows (that will be shown in the IFRAME), I am using an ADO
> > connection. Creating this connection takes a lots of time. What I would
> like
> > to do is to set this connection the first time I launch the HTA and
reuse
> it
> > every time I need it (including from the pages shown in the IFRAME).
> > I thought I had the a beginning of an answer when I read in one of the
ADO
> > pages of microsoft (www.microsoft.com/data/ado/sams/ch08.htm)(by the
way,
> is
> > the classid reported the correct one ?) that I could define a ADO
> connection
> > using the <OBJECT> tag (<OBJECT> NAME=cn CLSID="CLSID:....." </OBJECT>);
> > unfortunately when I tried to use this object (by using cn.open), I
only
> > got error messages saying that this object doesn't support this method.
> > Can anyone give me a hint ? Thanks.
> > John