I have the following package:

(* Wolfram Language Package *)

(* Created by the Wolfram Workbench Aug 13, 2015 *)

(* Exported symbols added here with SymbolName::usage *) 

OpenXxSQLConnection::usage="Open the connection to the Xx database."
CloseXxSQLConnection::usage="Closes the connection to the Xx database."

(* Implementation of the package *)

  If[! SQLConnectionUsableQ[XxSQLConnection],
   XxSQLConnection = OpenSQLConnection[JDBC["Microsoft SQL Server(jTDS)", "server"], "Catalog" -> "Xx"];




This is installed to the $BaseDirectory in an XxDataLink directory. There is a sub directory called Kernel with an init.m file with the following line Get[ "XxDataLink`XxDataLink`"].

In a new instance of Mathematica I do a Get (<<) on this package and try to open the database connection (no error messages).

<< "XxDataLink`"
conn = OpenXxSQLConnection[]
(* OpenXxSQLConnection[] *)

What am I doing wrong? I am expecting to get a connection to the database. I've added the jTDS DLL file so that can use SQL Server integrated security for the connection and the code works outside of the package.

OpenSQLConnection[JDBC["Microsoft SQL Server(jTDS)", "server"], "Catalog" -> "Xx"]
{SQLConnectionUsableQ[#], SQLConnectionOpenQ[#]} &[%]
(* {True, True} *)

Returns an open usable connection when run directly in a notebook. Not certain why I'm not getting one when I run it through the package. The package and DatabaseLink are loading with the Get as I can run OpenSQLConnection after I load XxDataLink without explicitly loading DatabaseLink in the notebook.

Mathematica 10.1 and Windows 7


Also tried in 10.2 and Windows 7 with the same results. Can anyone repeat this behavior? Could it be some sort of bug with the Mathematica DatabaseLink package? I'm thinking it wouldn't be since tons of people must have done this before me and had it work.


closed as off-topic by Sjoerd C. de Vries, m_goldberg, MarcoB, Michael E2, Mr.Wizard Aug 18 '15 at 3:49

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Sjoerd C. de Vries, m_goldberg, MarcoB, Michael E2, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ It might be that SQLConnectionUsableQ yields a definite a true or False only when given a real connection link as parameter. It might return unevaluated when not, causing the If branch to return unevaluated. $\endgroup$ – Sjoerd C. de Vries Aug 17 '15 at 18:01
  • $\begingroup$ @SjoerdC.deVries Nope. It returns false when not given connection. Tried that before I made function in the package. I just tested again to be certain with SQLConnectionUsableQ[x] returns (* Flase *) for uninitialised x. $\endgroup$ – Edmund Aug 17 '15 at 18:14
  • $\begingroup$ Is XxDataLink directory directly inside $BaseDirectory? Are you sure you have $BaseDirectory in your $Path, by default it's not. But if it's not, then you should get Get::noopen message, so there must be something else wrong. What does FindFile["XxDataLink`"] return? $\endgroup$ – jkuczm Aug 17 '15 at 18:20
  • 2
    $\begingroup$ Maybe you have some typo in your package, that you accidentally corrected when posting code in your question? Try copying the code from your post and paste it to your package, that's what I did and package worked. $\endgroup$ – jkuczm Aug 17 '15 at 19:25
  • 2
    $\begingroup$ @jkuczm Oh, for the love of Zeus!!! What I wouldn't give for some peer review in times like these. The gruesome pain has come to a close. It was a forsaken typo (and that f is well placed). $\endgroup$ – Edmund Aug 17 '15 at 19:49

Maybe try

If[! TrueQ[SQLConnectionUsableQ[XxSQLConnection]], ...
  • $\begingroup$ No dice. Still does not work. I would not have expected that to work since SQLConnectionUsableQ returns True or False. $\endgroup$ – Edmund Aug 17 '15 at 17:19
  • $\begingroup$ Maybe if conn is defined. What happens if it isn't defined? $\endgroup$ – Chris Degnen Aug 17 '15 at 17:20
  • $\begingroup$ I'm starting from a fresh loading of Mathematica (only have one instance open) so nothing is previously defined. $\endgroup$ – Edmund Aug 17 '15 at 17:22
  • 1
    $\begingroup$ How about << "XxDataLink`XxDataLink`" ? Although it shouldn't be necessary at all if your package is loaded in init.m. $\endgroup$ – Chris Degnen Aug 17 '15 at 17:37
  • $\begingroup$ Nope. That is not doing the trick either. The package syntax and locations appear correct. It is very odd. $\endgroup$ – Edmund Aug 17 '15 at 17:47

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