Pretty much every time I launch a new Mathematica session and attempt a connection to my MS SQL database which lives across a network connected by RJ45 cable the first attempt or two at connecting time out, then things work fine.
I connect as follows:
sqlGetConnection[sqlDatabase_] := Module[{sqlConnectionString},
sqlConnectionString = StringJoin[
"jdbc:jtds:sqlserver://",
sqlServerName,
sqlPortNumber,
If[StringLength[sqlDatabase] > 0, "/", ""],
sqlDatabase,
";instance=",
sqlServerInstance];
OpenSQLConnection[JDBC["net.sourceforge.jtds.jdbc.Driver", sqlConnectionString], "Username" -> sqlUserName, "Password" -> sqlPassword]
]
Note it is not the case that the server is not running and has to start on the first call: Once I establish a connection with the database, all works fine. Then I quit Mathematica, relaunch it, and I get the same timeout problem. So somehow, it seems related to launching Mathematica, not SQL server.
This occurs in several Mathematica programs I have written, where I use SQL. I dont keep the connection open for the life of a session. Typically, I Open-Do Something-Close for each SQL call. I religiously close the connection behind myself.
This is the typical error message:
JDBC::error: Network error IOException: Operation timed out >>
Versions: MS SQL 2012, Mathematica (on a Mac) 10.2.
Any suggestions?