Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have run into the following problem: when I try to run the following code in Mathematica 9 I get SQL connection error on all kernels. The code is:

ParallelTable[SQLExecute[conn, "Select 2+2"], {4}]

And the error message: SQLConnection::conn: Connection is not opened properly.

The connection itself works fine - I tested it. Also the above code used to work in Mathematica 7. On 8 a similar but more complex SQL request did not work.

I would appreciate any suggestions what I could do to solve this (tried distribute Definition on conn and also tried creating a list of connections and selecting one according to $KernelId).

share|improve this question
2  
Not sure but I think you would need to ParallelEvaluate the conn=OpenSQLConnection[...], so that each Kernel has it's own connection to the database. Note that this is different than creating a list of connections on the master and distributing them, which I definitely would not expect to work. I wonder how the above could work with version 7, though. Are you sure that with version 7 the ParallelTable was really executed in parallel? –  Albert Retey Feb 25 '13 at 13:24
    
just another comment to ring a bell, forgot that in my last. Sorry for the noise... –  Albert Retey Feb 25 '13 at 13:50
    
Thanks a lot, it seems this did the trick. About Mathematica 7: I am sure that it launched subKernels and did not give error messages, but I don't know if it actually used the subKernels or not. I will check it once i get my hands on it again. –  Vajk Feb 25 '13 at 14:50
add comment

1 Answer 1

up vote 0 down vote accepted

As it seems to solve the problem I'm moving my comment to an answer:

To make this work you need to open an independent connection from every parallel kernel. It is important the the call to OpenSQLConnection is evaluated on the parallel kernels, so generating a list of connection on the master and distributing these to the parallel kernels will not work. To generate the connections on the parallel kernels the most straightforward solution is to ParallelEvaluate something like conn=OpenSQLConnection[...]. This should work even if the parallel kernels run on different machines and platforms (as long as they can connect to the database). It is the database that will need to handle potential problems from simultaneous access from the parallel kernels, so you'll need a database system that supports concurrent access (which most but not all such systems do).

share|improve this answer
    
Thanks again for this! –  Vajk Mar 1 '13 at 7:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.