Answered Gadget works in IE, but blank when I install and run...

  • Monday, November 14, 2011 4:53 PM
     
     

    Hi

    I have a gadget that connects to an Access database, runs a select statement and returns the value to a div on my html page...

    This works perfectly in IE, but after I zip, install & run on the sidebar, it just comes up blank...

    I am guessing it may have something to do with running ActiveX..? I have tried disabling UAC and that hasn't worked...

    Can anyone help..?

    Cheers

All Replies

  • Monday, November 14, 2011 10:12 PM
     
     
    Using 'POST' at all?
  • Tuesday, November 15, 2011 6:55 AM
     
     

    Hi, sorry but not sure what that is... I have uploaded a copy of the project here... http://fileape.com/index.php?act=download&id=75wACGrRl3vK2aRf if you wanted to have a look...

    Cheers..!

  • Tuesday, November 15, 2011 7:52 AM
     
     

    Have you also created a gadget.xml file ?

    It's just that when I zip your index.html with the sample 'Hello World' gadget.xml file it looks pretty much like it does in a browser.

    Edit the html src in the gadget.xml so it looks like this:

       <base type="HTML" apiVersion="1.0.0" src="index.html" />

    • Edited by mystifeid Tuesday, November 15, 2011 7:55 AM
    • Edited by mystifeid Tuesday, November 15, 2011 8:17 AM
    •  
  • Tuesday, November 15, 2011 10:17 AM
     
      Has Code

    Hi

     

    Yeh, there is a gadget.xml file in there. It reads as follows...

    <?xml version="1.0" encoding="utf-8"?>
    <gadget>
      <name>SQLSAC</name>
      <namespace>LB</namespace>
      <version>1.0.0.0</version>
      <author name="LB">
        <info url="=" text="="/>
        <logo src="images/logo.png"/>
      </author>
      <copyright>2011</copyright>
      <description>SQL Row Count</description>
      <icons>
        <icon height="48" width="48" src="images/sql.png"/>
      </icons>
      <hosts>
        <host name="sidebar">
          <autoscaleDPI><!--_locComment_text="{Locked}"-->true</autoscaleDPI>
          <base type="HTML" apiVersion="1.0.0" src="sql.html"/>
          <permissions>Full</permissions>
          <platform minPlatformVersion="1.0"/>
          <defaultImage src="images/drag.png"/>
        </host>
      </hosts>
    </gadget>
    


    I have the source set to = "sql.html" I thought that was necessary as the filename I wanted to open was sql.html...

    Thought it might be something to do with allowing ActiveX (as IE makes me click to allow), but other gadgets that appear to use ActiveX work ok...

    Cheers

     

     

  • Tuesday, November 15, 2011 11:22 AM
     
     

    Yeah, well, that's yer problem. Does it load once you change the src to index.html ?

    Forget about ActiveX's until you start instantiating your own.

    Sidebar.exe reads the gadget.xml first. It must find the name of your main gadget html file. In your case it appears to be index.html but it can be anything.html. (The src file must be a html file.) All other files are referenced from your main gadget html file.

  • Tuesday, November 15, 2011 11:32 AM
     
     

    I tried changing it to index, but then it displayed nothing. I have put a screen shot below of how my folder looks. I reckon as my html is sql.html it needs that in the gadget.xml...

    Below is how it looks in IE...

    I'll do another reply to show how it looks when installed and running...

     

  • Tuesday, November 15, 2011 11:33 AM
     
     
    ???
    Cheers..!
  • Tuesday, November 15, 2011 11:43 AM
     
     
    Sorry, my download manager downloaded the wrong file the first time and it is getting late..
  • Tuesday, November 15, 2011 11:51 AM
     
     

    No probs :D

    Is there a right or wrong way to compile and install..? I'm just zipping all the files and renaming to sql.gadget. Then double clicking and installing...

     

  • Tuesday, November 15, 2011 12:16 PM
     
     

    Yeah, no that's all good.

    But in your css file you give data these attributes :

    #data {position:absolute;top:2px;left:2px;width:122px;height:92px;background-color:#FFEFB2;font-size:22pt;overflow:auto;}

    and in the html file you give data this inline style :

    <div id="data" style="position:absolute;top:75px;left:-1px;width:130px;text-align:center;z-index:10">

    There are a few conflicts there (eg top, left, width) and nothing to cope with them in the script. Try deleting the inline style completely. I haven't got an access database handy but it looks like it fixes the appearance.

    I think IE is realizing a mistake has been made and refuses to push the top down to 75px but the sidebar has no such hesitation.

    Also once upon a time all files had to be encoded with utf-8.

  • Tuesday, November 15, 2011 12:55 PM
     
      Has Code

    Thanks for the CSS help. I see what you mean, there's no point having styling in the html if I'm going to set it in the CSS...

    I have changed the HTML file to this...

    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=unicode"/>
        <script src="js/sql.js" type="text/javascript"></script>
        <link href="css/sql.css" rel="stylesheet" type="text/css" />
    
    <title>Test Database</title>
    
    </head>
    <body onload="showReports()">
        <div id="data">
     	<script language="JavaScript">
            	showReports();
        	</script>
        </div>
    </body>
    </html>
    
    


    And this is now giving me this when I run it...

     

    Appearance looking identical now. Just need the info...

     

    Test.mdb is only a one table, one column database with a few thousand records in. All I am trying to do is display a count of how many records are in a table in a certain database, ultimately...

  • Tuesday, November 15, 2011 1:13 PM
     
      Has Code

    You don't need this either:

    <script language="JavaScript">
            	showReports();
        	</script>

    so you should be able to shorten the html to

    <html>
    <head>
     <meta http-equiv="Content-Type" content="text/html; charset=unicode"/>
     <script src="js/sql.js" type="text/javascript"></script>
     <link href="css/sql.css" rel="stylesheet" type="text/css" />
     <title>Test Database</title>
    </head>
    <body onload="showReports()">
      <div id="data"></div>
    </body>
    </html>

    Let us know how you go getting it to cough up the goods.

     

     

  • Tuesday, November 15, 2011 1:26 PM
     
     

    Done. Looks a lot neater now...

    Not sure where it's even failing. Can't tell if it's not making the connection, not getting the data or not displaying the data...

    Thanks for all your help and tips. I'll post back if I end up getting it working...

    Cheers..!

  • Tuesday, November 15, 2011 1:38 PM
     
     

    Pretty sure there's no alert in sidebarland so delete "alert(ex.message);"

    It's easy to find where it's failing. Just move this line thru your script, restarting each time :

    data.innerText="works up to here";

  • Tuesday, November 15, 2011 1:53 PM
     
      Has Code

    Great idea. I did that and ended up changing the js file to this...

     

        function getAdoDb(strAdoType) {
            if (window.ActiveXObject) {
                return new ActiveXObject(strAdoType);
    
            }
            else {
                return ActiveXObject(strAdoType);
    
            }
        }
    
    function showReports() {
    	
        var adOpenDynamic = 2;
        var adLockOptimistic = 3;
    
    
    
        /* Path of database.
        */
        var strDbPath = "\Test.mdb";
    
        /*
        Here is the ConnectionString for Microsoft Access.
        If you want to use SQL or other databases, you hav to change the connection string..
        eg: SQL => var conn_str = "Provider=sqloledb; Data Source=itdev; Initial Catalog=pubs; User ID=sa;Password=yourpassword";
        */
        var conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDbPath;
    
    
                 
                 try {
                     var strHtml = "";
    //                 strHtml += "<table cellpadding=0 cellspacing=0 border=1 width= '100%' align=center>";
    //                 strHtml += "<tr ><td align=center colspan=4><b>Sample Database Records</b></td></tr>";
    
                     //Database Connection
                     var conn = getAdoDb("ADODB.Connection");
                     conn.open(conn_str, "", "");
    
                     //Recordset
                     var rs = new ActiveXObject("ADODB.Recordset");
                     //strQuery = "SELECT * FROM SampleTable";
                     strQuery = "SELECT COUNT (*) FROM Customer";
                     rs.open(strQuery, conn, adOpenDynamic, adLockOptimistic);
    
                     if (!rs.bof) {
                         rs.MoveFirst();
                         while (!rs.eof) {
                             //strHtml += "<tr>";
                             //strHtml += " <td><Font face ='tahoma'>" + rs.fields(0).value + "</font></td>";
                             //strHtml += " <td><Font face ='tahoma'>" + rs.fields(1).value + "</font></td>";
                             //strHtml += " <td><Font face ='tahoma'>" + rs.fields(2).value + "</font></td>";
                             //strHtml += " <td><Font face ='tahoma'>" + rs.fields(3).value + "</font></td>";
                             //strHtml += "</tr>";
    
                             strHtml += rs.fields(0).value
                             
                           
                             rs.MoveNext();
                         }
                     }
                     else {
                         //No Records.
                         //strHtml += "<tr colspan=1><td align=center><font color=red>No Records.</font></td></tr>";
                     }
                     conn.close();
                     //strHtml += "</table>";
                     //document.write(strHtml);
                     document.getElementById("data").innerHTML = strHtml;
                 } catch (ex) {
                     
    		data.innerText="works up to here";
                 }
             }
            
    
    
    

    It now shows "works up to here". Would I be correct in saying that it's failing on the Try/Catch..?

  • Tuesday, November 15, 2011 2:04 PM
     
     

    Just on the try - it's managing the catch now.

    So get rid of the try catch and starting at the beginning insert the line

    data.innerText="works up to here";

    after the first line, save and restart. If you see the words move the line so it follows the second line, save and restart. If you see the words move it so it follows the third line,save and restart and so on. Eventually you will not see the words and that should give you a pretty good idea which statement is giving you grief.

  • Tuesday, November 15, 2011 2:12 PM
     
      Has Code

    That worked. I can see that this is the line that is making it fail now is this one...

     

    conn.open(conn_str, "", "");
    

    So it's failing when it tries to open the connection. That is a bit weird then if IE is not having any problems...

  • Tuesday, November 15, 2011 2:16 PM
     
     Answered Has Code

    Oh wait, backslashes in paths have to be escaped (with a backslash) I think so things like

    var strDbPath = "\Test.mdb";

    should be written like

    var strDbPath = "\\Test.mdb";
    • Marked As Answer by Betty8080 Tuesday, November 15, 2011 2:21 PM
    •  
  • Tuesday, November 15, 2011 2:21 PM
     
     
    That worked..!!
    The paths had been really confusing me as I had to copy everything in the same folder to get it to work in IE. Now you've said that, it makes sense why I was having problems early on...
    Thanks loads for helping me with this...
    Cheers..!
  • Tuesday, November 15, 2011 2:28 PM
     
     
    Cool, now you can go berserk !
  • Wednesday, November 16, 2011 2:35 AM
     
     

    This also would've helped :

    try{

    [whatever]

    }

    catch(ex){

    data.innerText=ex.message;

    }