More info from stms :
Short Text
SQL error "SQL code: -10108" occurred while accessing table "CDHDR".
What happened?
Database error text: "SQL message: Session has been reconnected."
Return value of the database layer: "SQL dbsl rc: 99"
The problem is that client is running this code through the job in which I am not available to debug it. All I know is that it is working for other countries selected but for some specific it is not so the question is :
Was it a temporary connection error between two servers or is it data overload issue due to SELECT statement?
At the moment I am not really sure which thing I have to look on the system, the same program once produced the error for exceeding the limit in the db query ( > 10 minutes) so this might be related to system configuration or what?
Thanks in advance
Error I keep getting:
Lost connection to MySQL server during query
My code:
def runDBQuery(bl_sel):
dbResponse = []
bl_cur.execute(bl_sel)
myresult2 = bl_cur.fetchall()
dbResponse.append(myresult2)
return(dbResponse)
if __name__ == '__main__':
p1abl_sel = bl_sel_template.replace("{firstupc}",p1afirstupc).replace("{lastupc}",p1alastupc)
p2abl_sel = bl_sel_template.replace("{firstupc}",p2afirstupc).replace("{lastupc}",p2alastupc)
list_of_columns = [ p1abl_sel, p2abl_sel ]
#list_of_columns = [ p1abl_sel ]
p = Pool(processes=2)
data = p.map(runDBQuery, [i for i in list_of_columns])
# the 4 lines below are my failed attempts to try to resolve this.
bl_cur.close()
if cur and con:
cur.close()
con.close()
p.close()
print(data)
Whenever I uncomment the list_of_columns so there's only one element(query) in the list, it works and I get back a response from the DB. However, if I have more than one element in the list, I encounter the listed error.
Can anyone help me solve this problem?
The problem can be not in your code.
MySQL error "Lost connection to MySQL server during query" can accrue because of reading timeout. It can be either on the client side or mysql server configuration
MySQL
max_execution_time: The execution timeout for SELECT statements, in milliseconds. If the value is 0, timeouts are not enabled.
connect_timeout: Number of seconds the mysqld server waits for a connect packet before responding with 'Bad handshake'
interactive_timeout Number of seconds the server waits for activity on an interactive connection before closing it
wait_timeout Number of seconds the server waits for activity on a connection before closing it
https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_execution_time
For pyMysql check read_timeout
https://pymysql.readthedocs.io/en/latest/modules/connections.html
I’m trying to open an SQL instance within a driver which uses the DB2Driver from IBM.
The interesting part is that when I include:
def DB2Driver = new DB2Driver()
That initializes just fine.
But when I do
Sql.newInstance(info.getHost(), info.getConnectionMetaData().getParameterValue('username'), info.getConnectionMetaData().getParameterValue('password'), info.getConnectionMetaData().getParameterValue('driverClass'))
Or
Sql.newInstance(info.getHost(), info.getConnectionMetaData().getParameterValue('username'), info.getConnectionMetaData().getParameterValue('password'), 'com.ibm.db2.jcc.DB2Driver')
It will fail to open a SQL connection, saying that a suitable driver isn't found. How can I get the connection to DB2 to open?
Assuming that you are using a groovy script with #Grab and #Grapes annotations, you probably need configure Grape for JDBC drivers:
Because of the way JDBC drivers are loaded, you’ll need to configure Grape to attach JDBC driver dependencies to the system class loader
In groovy.sql.Sql the JDBC DriverManager is used to get a connection: DriverManager.getConnection(). Since it needs the driver depencencies attached to the system class loader, you need to do it with #GrabConfig.
For example, this script
#Grapes([
#Grab(group='org.hsqldb', module='hsqldb', version='2.3.2'),
])
import groovy.sql.Sql
def sql = Sql.newInstance('jdbc:hsqldb:mem:testdb', 'sa', '', 'org.hsqldb.jdbcDriver')
println 'SQL connection ready'
fails with the exception java.sql.SQLException: No suitable driver found for jdbc:hsqldb:mem:testdb, but with
#Grapes([
#Grab(group='org.hsqldb', module='hsqldb', version='2.3.2'),
#GrabConfig(systemClassLoader=true)
])
it works perfectly.
I'm using Play framework 2.x with SQL driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
I'm trying to run a simple query:
SELECT [org].[name] FROM [ref].[organisations_bak] AS org
but I get the following error:
play.api.Application$$anon$1: Execution exception[[SQLServerException: Invalid object name 'ref.organisations_bak'.]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10-2.2.2.jar:2.2.2]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10-2.2.2.jar:2.2.2]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:165) [play_2.10-2.2.2.jar:2.2.2]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$12$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:162) [play_2.10-2.2.2.jar:2.2.2]
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33) [scala-library-2.10.3.jar:na]
at scala.util.Failure$$anonfun$recover$1.apply(Try.scala:185) [scala-library-2.10.3.jar:na]
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'ref.organisations_bak'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216) ~[sqljdbc4-4.0.2206.100.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515) ~[sqljdbc4-4.0.2206.100.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:792) ~[sqljdbc4-4.0.2206.100.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:689) ~[sqljdbc4-4.0.2206.100.jar:na]
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696) ~[sqljdbc4-4.0.2206.100.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715) ~[sqljdbc4-4.0.2206.100.jar:na]
I need to use the schema reference in my queries but I cant even get a simple query like this to work on my play app, simple queries without schema references work fine
SELECT name FROM organisations_bak
My Scala code looks like this:
import java.sql.ResultSet
import play.api.db.DB
DB.withConnection {
conn =>
val res = conn.createStatement.execute("SELECT [org].[name] FROM [ref].[organisations_bak] AS org")
}
Any help would be appreciated.
Thanks
In my case the issue was different user permissions. The server I used for development has been setup in some weird way that my user didn't have the permission to access the [ref] schema.
Just as a test I switched over to an AWS RDS SQL Server instance with the default DBA (owner) user settings and everything worked.
This means that the library and the code works it's my server that's at fault, but that's another issue.
try using
SELECT [org].[name] FROM [ref].[dbo].[organisations_bak] AS org
I am trying to connect an Oracle database to Mathematica 8. Another question already says how it can be done in for a MySQL database but it does not work for me:
Needs["DatabaseLink"] AND conn = OpenSQLConnection[JDBC["MySQL(Connector/J)",
"yourserver/yourdatabase"], "Username" -> "yourusername", "Password" -> "yourpassword"]
The following information is available for me on my desktop:
filepath = "C:\oracle\ora92\network\ADMIN\tnsnames.ora"; HOST; PORT; username; password;
conn = OpenSQLConnection[JDBC["MySQL(Connector/J)", HOST], "Username" -> username, "Password" -> password]
Error message: JDBC::error:
Communications link failure The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server. >>
Does anyone know how I can connect or continue?
Mathematica 8 does not come pre-equipped with an Oracle driver, a fact that can be verified by evaluating these expressions:
Needs["DatabaseLink`"]
JDBCDriverNames[]
(*
Out[2]= {Microsoft Access(ODBC),hsqldb,HSQL(Memory),HSQL(Server),
HSQL(Server+TLS),HSQL(Standalone),HSQL(Webserver),HSQL(Webserver+TLS),
jtds_sqlserver,jtds_sybase,mysql,MySQL(Connector/J),ODBC(DSN),odbc,
PostgreSQL,Microsoft SQL Server(jTDS),Sybase(jTDS),HSQL 2.0.1}
*)
We will have to follow the instructions in the Mathematica documentation that describes how to install a new JDBC driver.
First, we will have to create a new resource directory in which to place the necessary JDBC driver JAR file:
$jarDirectory =
CreateDirectory #
FileNameJoin #
{$UserBaseDirectory, "Applications", "Oracle", "Java"}
Next, we must select a JDBC driver to use. Visit the relevant Oracle page to find the correct JDBC driver for your database.
Chose a driver version that is compatible with Java 6, the version that Mathematica 8 uses internally. For this example, I chose to use the Oracle 11.2.0.2.0 driver for Java 6. Download the file and then move it into the resource directory just created:
SystemOpen[$jarDirectory]
Next, we will create a JDBC driver configuration file so that the new driver is registered with Mathematica:
$configDirectory =
CreateDirectory #
FileNameJoin #
{$UserBaseDirectory, "Applications", "Oracle", "DatabaseResources"}
Export[
FileNameJoin # {$configDirectory, "Oracle.m"}
, JDBCDriver[
"Name" -> "Oracle"
, "Driver" -> "oracle.jdbc.driver.OracleDriver"
, "Protocol" -> "jdbc:oracle:thin:#"
, "Version" -> 1
]
, "Text"
]
The driver is now installed:
JDBCDriverNames[]
(*
Out[9]= {Oracle,Microsoft Access(ODBC),hsqldb,HSQL(Memory),HSQL(Server),
HSQL(Server+TLS),HSQL(Standalone),HSQL(Webserver),HSQL(Webserver+TLS),
jtds_sqlserver,jtds_sybase,mysql,MySQL(Connector/J),ODBC(DSN),odbc,
PostgreSQL,Microsoft SQL Server(jTDS),Sybase(jTDS),HSQL 2.0.1}
*)
If the fates are smiling, we can now establish a connection and execute an SQL query:
$connection =
OpenSQLConnection[
JDBC["Oracle", "myserver:1521:mysid"]
, "Username" -> "scott"
, "Password" -> "tiger"
]
SQLExecute[$connection, "SELECT 'success!' FROM DUAL"]
... where myserver is the database server name, 1521 is the listener port number and mysid is the Oracle System ID (SID).
Oracle JDBC URLs come in many forms. For details, take a look at the Oracle FAQ.
I suspect that you are using the wrong JDBC driver - you should be using the Oracle JDBC driver, rather than MySQL one. When I was using DatabaseLink to connect to an Oracle database, I used this command:
OpenSQLConnection[
JDBC[
"oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:#server:port:dbname"
],
"Name" -> "dbname",
"Username" -> "YourUserName",
"Password" -> "YourPassword"
]
You should make sure to put the proper Oracle JDBC driver (corresponding to your Oracle db version) into a place where Mathematica can find it. This procedure is described in the documentation for the DatabaseLink, section JDBC Connections. You can test which JDBC drivers are visible to Mathematica by executing JDBCDrivers[]. Make sure that you install and use the correct driver corresponding to your DB version, b.t.w. - incorrect driver versions may result in very nasty and non-obvious bugs (this is unrelated to Mathematica).
My guess would be that you shouldn't use MySQL JBDC connections for Oracle. Although it is for Mathematica 5.2, here is an article that you perhaps can use as something to go from.
I've barely used Mathematica, and certainly not with a database, but from that page, it looks like you can do this:
OpenSQLConnection[JDBC["oracle","server.business.com:1999"],
Username -> "you"]
Whilst the answer from WReach above is correct it may also be helpful to know that there are 2 additional lines that are useful - namely to make sure Jlink is loaded and the Java ClassPath is correct and pointing to your oracle jdbc6.jar file.
Needs["JLink`"]
AddToClassPath[
FileNameJoin[{$UserBaseDirectory, "Applications", "Oracle",
"Java"}]];
or if using the answer verbatim just
Needs["JLink`"]
AddToClassPath[$jarDirectory];