Importing a Database to MATLAB error - connection

I am trying to import tables to my MATLAB workspace and it keeps throwing me an error, "Undefined function or method 'fetch' for input arguments of type 'struct'."
This is my code that i am trying to execute:
dyn_conformer = exec(conn, 'SELECT * FROM dyn_conformer');
rs =fetch(dyn_conformer);
When i opened the object in the workspace, it stated that it was "Invalid or closed connection".
However, previously i manage to import other tables and it seemed to execute perfectly (they are stored as a cursor object). All of a sudden, its throwing an error for other tables that i am trying to import.
I am connected to the datatabase, conn = database('postgres','username','password','org.postgresql.Driver','jdbc:postgresql://localhost:5433/postgres');.

I would recommend you to check for existing of connection variable and that it is the properly established connection before running exec. You can do it like this:
if ~exist('conn','var') || ~isconnection(conn)
conn = database('postgres','username','password','org.postgresql.Driver',...
'jdbc:postgresql://localhost:5433/postgres');
else
dyn_conformer = exec(conn, 'SELECT * FROM dyn_conformer');
rs =fetch(dyn_conformer);
end

Related

Error "Attempt to reclose a closed cursor" executing a query using FireDac

I have a problem with a connection to a database in Firebird 2.0
I'm using Delphi Berlin and the connection is made using FireDac.
In fact the connection test with the FDConnection1 I do it correctly and if I do a FDConnection1.ExecSQL (v_SQL, []) (where v_SQL I have a delete or an insert, it does it correctly.
The problem appears when I put a fdQuery1 and if I double click on it and on the tab I put a simple query:
select * from tipo_cliente
then clicking on the EXECUTE button gives me the following error (and I can not find any of it on the internet):
[FireDac][Phys][FB]Dynamic SQL Error
SQL error code = -501
Attempt to reclose a closed cursor
Of course this query if I take it to some Firebird manager, like IBmanager, works correctly

SSIS Execute SQL Task MCH1202 Error

In an SSIS package I am developing I have an execute SQL task which uses an ODBC Connect to a database on iSeries AS400 the task calls a stored procedure:
{CALL DOCTRACK.CORRFEED (?,?,?,? )}
The stored procedure takes 4 parameters the first 2 input and last 2 output.
The Data types of the parameters are char(8), integer, decimal(7,0) and char(80) respectively. The parameters are mapped to the variables in the package that match the data types.
When I run the package I get the following error message on the Execute SQL Task:
[Execute SQL Task] Error: Executing the query "{CALL DOCTRACK.CORRFEED (?,?,?,? )}"
failed with the following error: "[IBM][System i Access ODBC Driver][DB2 for i5/OS]CEE9901 -
Application error. MCH1202 unmonitored by CORRFEED at statement 0000000020, instruction X'0000'.".
Possible failure reasons: Problems with the query, "ResultSet" property not set correctly,
parameters not set correctly, or connection not established correctly.
Does anyone have any ideas what may be causing the error?

Executing a SSIS package from stored procedure is timing out

I have a conundrum and I'm stumped and hoping y'all can help.
Here is my scenario: I am loading data into our database through a web interface. First, I upload the file to the SQL box, then I call the script which extracts and loads the data into SQL.
I recently changed this process so that now, instead of executing the package from within the web application, I am calling a stored procedure to execute the script.
Here is the core of my code:
CREATE PROCEDURE [dbo].[ExecuteSsisPackage]
#Package NVARCHAR(100),
AS
BEGIN
SET NOCOUNT ON;
DECLARE #executionID BIGINT
EXEC SSISDB.catalog.create_execution
#folder_name = 'Imports', -- nvarchar(128)
#project_name = 'DataImports, -- nvarchar(128)
#package_name = #Package, -- nvarchar(260)
#use32bitruntime = 1, -- bit
#execution_id = #executionID OUTPUT -- bigint
SELECT #executionId
EXEC [SSISDB].[catalog].[set_execution_parameter_value] #executionId, 50, N'SYNCHRONIZED', #parameter_value = 1 -- turn on synchronization
EXEC ssisdb.catalog.start_execution #executionID;
RETURN (#executionID)
END
Here is the odd part: when I run the stored procedure from management studio it executes fine. However, when I execute this from the web application it times out. But, if I turn OFF synchronization it executes just fine through the web app. The problem with disabling synchronization is that I need to pull some summary info off the data after it has been loaded.
I've even tried rolling my own 'synchronization' from a post I found:
DECLARE #status AS BIGINT = 1;
WHILE(#status = 1 OR #status = 2 OR #status = 5 OR #status= 8)
BEGIN
PRINT 'Status: ' + CAST(#status AS VARCHAR(10))
PRINT 'waiting 2 seconds for Package to finish'
WAITFOR DELAY '00:00:2';
SET #status = (SELECT [Status] FROM SSISDB.[catalog].[executions]
WHERE execution_id = #executionID);
END
PRINT 'Exit Status: ' + CAST(#status AS VARCHAR(10))
This also times out. I did some digging and found that when the SP is executing from the web (but not management studio) there is a lock: LCK_M_S and the wait_resource is: KEY: 9:72057594041532416 (d28bcaafb8df). Again, this only occurs when executing the SP from the web app.
Some more digging unearthed the culprit for the lock. It is the PK_Operations key of the SSISDB.internal.operations table. This is the conundrum. Any ideas why this occurs only through the web and when synchronized it turned on??

Neo4j: Java API IndexHits<Node>.size() is 0

I'm trying to use the Java API for Neo4j but I seem to be stuck at IndexHits. If I query the DB with Cypher using
START n=node:types(type="Process") RETURN n;
I get all 2087 nodes of type "Process".
In my application I have the following lines
Index<Node> nodeIndex = db.index().forNodes("types");
IndexHits<Node> hits = nodeIndex.get("type", "Process");
System.out.println("Node index size: " + hits.size());
which leads my console to spit out a value of 0. Here, db is of course an instance of GraphDatabaseService.
I expected an object that included all 2087 nodes. What am I doing wrong?
The .size() question is just the prelude to my iterator
for(Node process : hits) { ... }
but that does not much when hits.size() == 0. According to http://api.neo4j.org/1.9.2/org/neo4j/graphdb/index/IndexHits.html this should be possible, provided there is something in hits.
Thanks in advance for your help.
I figured it out. Man, I feel so embarrassed...
It so happens that I had set up the DB_PATH to my default data folder, whereas the default storage folder is the default data folder plus graph.db. When I tried to run the code from that corrected DB_PATH I got an error saying that a lock file was in place because the Neo4j server was running. After shutting it down it worked perfectly.
So, if you happen to see the following error, just stop the server and run the code again:
Caused by: org.neo4j.kernel.StoreLockException: Could not create lock file
at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:74)
at org.neo4j.kernel.StoreLockerLifecycleAdapter.start(StoreLockerLifecycleAdapter.java:40)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:491)
I found on several forums that you cannot run the Neo4j server and use the Java API to query it at the same time.

Multiple-step OLE DB operation generated errors [duplicate]

Dim NorthWindOledbConnection As String = "Provider=SQLOLEDB;DataSOurce=SARAN-PC\SQLEXPRESS;Integrated Security=ssp1;InitialCatalog=Sara"
Dim rs As New ADODB.Recordset()
rs.Open("select * from SecUserPassword", NorthWindOledbConnection, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic)
i tried to run this above code in visual studio 2008 - it shows the following error:
"Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done"
Firstly, don't use ADO in VB.NET. Use ADO.NET.
Other than that, create a proper Connection object instead of passing around a string.
And fix your connection string. It's SSPI, not SSP1. And it's Data Source, not DataSOurce. And it's Initial Catalog, not InitialCatalog.
You are using a very very very old way to access a Database that has been used with Visual Basic 6 and older.
Check to use ADO.NET instead of old ADO. For example you can use this code that is "similar" to the code you are using (but is not the best way to access the data on VS2008)
OleDbConnection con= New OleDbConnection( **Your Connection String** )
con.Open()
Dim command As OleDbCommand = New OleDbCommand("select * from SecUserPassword", con)
sqlCommand .CommandType = CommandType.Text
Dim reader As OleDbDataReader = TheCommand.ExecuteReader()
While reader.Read()
System.Console.Write(reader(** Your Table Field Name** ).ToString())
End While
con.Close()
To view how to create a correct connection String see the site http://www.connectionstrings.com/
If you want to access to an SQL Server database also you can use the SQLClient namespace instead the OleDb. For example System.Data.SqlClient.SqlConnection instead the OleDbConnection to provide better performance for SQL Server
The link below is an article that gives a great breakdown of the 6 scenarios this error message can occur:
Scenario 1 - Error occurs when trying to insert data into a database
Scenario 2 - Error occurs when trying to open an ADO connection
Scenario 3 - Error occurs inserting data into Access, where a fieldname has a space
Scenario 4 - Error occurs inserting data into Access, when using adLockBatchOptimistic
Scenario 5 - Error occurs inserting data into Access, when using Jet.OLEDB.3.51 or ODBC driver (not Jet.OLEDB.4.0)
Scenario 6 - Error occurs when using a Command object and Parameters
http://www.adopenstatic.com/faq/80040e21.asp
Hope it may help others that may be facing the same issue.

Resources