[ MATLAB + SQL Server ] Slow performance when fetching data

Hi all
I have a problem fetching data from a SQL database. I have tried using JDBC 4.0 and, as illustrated below, the .NET way.
import System.Data.SqlClient.*
NET.addAssembly('System.Data');
conn = SqlConnection('Data Source=myServer;Initial Catalog=myDatabase;Integrated Security=true');
conn.Open();
q = SqlCommand('select top 10000 myNumber from myTable', conn);
r = q.ExecuteReader();
data = zeros(1,10000);
tic
while r.Read()
r.GetFloat(0);
end
toc
r.Close()
conn.Close()
My problem is that the while-loop performs quite slowly. It takes up to 8-10 seconds to fetch the data.
One might ask why I think this is slow, but if I perform the very same query through SQL Management Studio it takes 0.01 seconds to fetch and present the 10000 rows.
So my question is: Why is MATLAB so much slower in fetching 10000 rows? It's obviously not the database or the LAN-connection which performs badly.

1 Comment

Apparently multiple calls to .NET from Matlab can be slow, see here. To quote:
Bottom line is that there is a significant overhead in calling a .NET method from within Matlab. It is important to make the .NET api "chunky" instead of "chatty".
Could this be the problem?

Sign in to comment.

Answers (0)

Products

Asked:

on 6 Mar 2013

Commented:

KAE
on 7 Mar 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!