2010-02-26

Mathematica Debugger Traps

When I first started using WorkBench 2.0 and Mathematica 7.0.1 I found the operation of the debugger flaky.  However I have identified a number of issues have helped me.

1 My problem was due to using a global connection in the module:

conn=OpenSQLConnection[…

This then prevents the debugger working.  I have now reworked my code so that I don’t use this type of connection. 

I have tested whether it is expensive to open a SQL connection on every call or if you do it just once for a group of calls.  Doing 10 simple queries took 1.7 seconds if the connection was opend and closed every time and ca 1 second if it was only opened once.  So for the generation of reports I am going to avoid the considerable work involved in doing two headers and wait until I can generate them automatically.

2 Timing.  You have to wait until the Workbench has finished loading.  This takes a number of seconds and you can easily start executing code in the opened notebook first.  If you do that the bottom right of the workbench screen will look like this:

workbenchScreenShot

The input number will be 2 rather 7 or 8 which is normal if the debugger is going to work.

3 I tried SVN addin to the workbench and that was a bad idea.  I had to uninstall and reinstall workbench to get back a working version.  I saw a post where Wolfram are working on the SVN version so I hope that comes through.

4 In the debug screen I make sure I delete other debug activities before starting a new debugging session.

5 Be good about default directories.  I tried a different directory for the module and the debugger wouldn’t breakpoint at it.  Moving it to the normal directory worked fine.

2010-02-12

Formatting tables in Mathematica reports,

I have come across someone who is doing something very similar in producing formatted reports:

http://www.scientificarts.com/formatting/formatting.html

It appears to be difficult to use TableForm when generating reports in created notebook reports and in the above example they have a work around.

2010-02-11

Creating Monkey reports in Mathematica

What I am after is a simple way to generate reports or actually carry out work based on some user input which can be carried out in Mathematica Pro.  I have struggled with an apparent interaction between long runnng sql queries and Dynamic Module which means that the execution has been unreliable when using Dynamic modules.

I created a demo report that allows you on Mathematica to push a button, request some input and generate a report .  The issue is that does not work very nicely in Player Pro as although there is a nice button to press you need to evaluate all the code.

I have now converted this into a number of files and successfully deployed to a Mathematica Player Pro.  i have stored the files in google docs so they can be downloaded.

The demo files are:

Having got a working notebook I did the following:

  1. Converted the library code to initialisation cells.  This created an initialisation package.
  2. Converted the auto saved initialisation package “report.m” to a package by adding BeginPackage,usage info for main function, Begin[`private`],End and End package.
  3. Convert the package to an encrypted package using the helper.  You need an encrypted needs when running on Player Pro
  4. Converted the report to just a single button with no extra code.  It needs the encrypted package.  One trick is to hide the code by removing the Cell –>Cell Properties open flag.
  5. Copy the encrypted packaged and button file to another system and I have a working tool.

Good news.

2010-02-10

Options for connecting Mathematica to a MS SQL server

The following is just an example of connecting to a SQL database (actual names changed slightly)  Also showing the slightly naughty habit of using the user sa.

In[1]:= Needs["DatabaseLink`"]

In[2]:= conn =
OpenSQLConnection[JDBC["Microsoft SQL Server(jTDS)", "MyServer"],
  "Catalog" -> "MyDemo", "Username" -> "sa",
  "Password" -> "RubyPane"]

Out[2]= SQLConnection[2, "Open", "Catalog" -> "MyServer",
"TransactionIsolationLevel" -> "ReadCommitted"]

This is a useful link for getting SQLExpress to work (basically don't try the integrated security):

http://softwaresalariman.blogspot.com/2007/04/jdbc-to-sql-server-express.html

Which gets me to:

s[] := OpenSQLConnection[
  JDBC["Microsoft SQL Server(jTDS)",
   "127.0.0.1:1433/Test;user=sa;password=sa"],
  "Catalog" -> "TestTercero", "User" -> "sa", "Password" -> "sa"]