OdbcConnection myConn = new OdbcConnection(); myConn.ConnectionString = "DSN=test370; //myConn.ConnectionString = "DSN=Sample C/ODBC 32 bit;"; try { //connecting Console.WriteLine("Connecting " + DateTime.Now); myConn.Open(); Console.WriteLine("Connected " + DateTime.Now); string SQLstring = "SELECT * FROM Productiestuklijstregel"; OdbcCommand myCommand = new OdbcCommand(SQLstring ,myConn); Console.WriteLine("Execute query " + DateTime.Now); //execute query OdbcDataReader myReader = myCommand.ExecuteReader(); Console.WriteLine("Query executed " + DateTime.Now); //table Console.WriteLine("Showing data " + DateTime.Now); DataTable dTable = new DataTable("List Records"); //columns for (int fCount = 0; fCount < myReader.FieldCount; fCount++) { dTable.Columns.Add(new DataColumn(myReader.GetName(fCount))); } //data in table DataRow dRow; int i = 0; while (myReader.Read()) { dRow = dTable.NewRow(); for (int k = 0; k < myReader.FieldCount; k++) { dRow[k] = myReader.GetValue(k); } dTable.Rows.Add(dRow); i++; } //showing data dataGrid1.SetDataBinding(dTable,null); Console.WriteLine("Done showing data " + DateTime.Now); Console.WriteLine(dTable.Rows.Count + " records fetched"); //disconnecting myConn.Close(); } catch (Exception k) { MessageBox.Show(k.ToString()); }
executing query takes 11 seconds and 11 seconds to show the data in a datagridConnecting 25-4-2006 8:54:28
Connected 25-4-2006 8:54:29
Execute query 25-4-2006 8:54:29
Query executed 25-4-2006 8:54:40
Showing data 25-4-2006 8:54:40
'temp.exe': Loaded 'c:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll', No symbols loaded.
Done showing data 25-4-2006 8:54:51
8685 records fetched
executing query takes 5 seconds and 1min 13seconds to show the data in a datagrid <-- like wtfConnecting 25-4-2006 8:57:34
Connected 25-4-2006 8:57:34
Execute Query 25-4-2006 8:57:34
Query executed 25-4-2006 8:57:39
Showing data 25-4-2006 8:57:39
'temp.exe': Loaded 'c:\windows\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll', No symbols loaded.
Done showing data 25-4-2006 8:58:52
9319 records fetched
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
i've tested the performance couple of times.
Connect + execute and then execute again (connection is still open) but no performance gain.
I've set the cache to 30000KB (max).
Is there maybe a way to fetch the data in 1 function instead of going trough the records 1 by 1 (and fields 1 by 1) ?
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
I've commented the myConn.Close(); line
To execute a 2nd time the query the reader must be closed by myReader.Close(). at that time i get a System error.
so i apparently the connection was closed @ the 2nd time.
But i dont know why there's a problem with the connection. Only the Read part is really slow.
http://www.autocloseidle.com
query
No gain
SELECT * FROM Productiestuklijstregel ORDER BY Type, Nr_
http://www.autocloseidle.com
Use ORDER BY to suggest to the C/ODBC driver what key to use. Some keys have long series of fields, you don't have to specify all of them, just specify the first few.
Example, in "Sales Invoice Line" table, you will find the following keys:
Blanket Order No.,Blanket Order Line No.
Sell-to Customer No.,Type,Document No.
Sell-to Customer No.
Lets say you wanted a posted invoice with a certain "Document No.", you cannot use:
If you do, a manual sort will occur because none of the keys above starts with "Document No.". You will have to use the following:
In case you don't need "Document No.", you can omit it, but you cannot omit "Type" and keep "Document No.", that is, omitting a field in the beginning or in the middle of a key without removing the rest of the key.
Note: To see the list of keys for a particular table, go to Object Designer, open a table using "Run" button, then click on the sort icon on the toolbar. You could also see it in File-->Database-->Information-->Tables.
http://www.autocloseidle.com
Production BOM no. , Version Code , Line No
Type, No
so i changed the sql query:
SELECT * FROM Production BOM Line ORDER BY Type, No_
as u can see the query didnt became any faster. and the showing data neither.
I think the problem isnt at the query but at the data fetching. anyone know C# and can enlight me about this fuzzy stuff :P