Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've installed SQL Express 2014 with all of its tools and created a instance (SQLEXPRESS) with Windows Authentication. Then I created a table named dbo.doc in the master database with 18 columns and entered 7731 entries in it.
I started a new Windows Form Project in Visual Studio Express (Community) 2015.
I placed on the Form Designer a DataGridView, BindingSource and BindingNavigator data controls. Then double pressed the form to send me to the load event of the form and typed the following code to load the data:
C#
SqlConnection con = new SqlConnection();
            SqlCommand comm = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            con.ConnectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=master;Integrated Security=SSPI;";
            comm.Connection = con;
            comm.CommandText = "SELECT * FROM doc";//[dbo].[doc]
            da.SelectCommand = comm;
            DataTable dt = new DataTable();
            da.Fill(dt);
            bSMain.DataSource = dt;//BindingSource
            bNMain.BindingSource = bSMain;//BindingNavigator
            dGVMain.DataSource = bSMain;//DataGridView

I started the code and I had to wait 20-30 seconds to load the data. I went in SQL Server Managment Studio and typed:
use master<br />
select * from doc<br />
go

The results came for less than a half of a second. I went in Visual Studio and from Tools - SQL Server - New Query wrote the same code and it loaded for the same time.
I've tried everything I could to find from other similar questions including repair and reinstalling SQL Server and Visual Studio, making new project, loading the data from console, with connected architecture, different connection strings, different commands, mixed mode authentication with odbc driver, compiling a release build, starting as administator, turning off any security options, checking the sql server and visual studio sql settings and many others, but it was loading 20-30 seconds every time from the code and less than a second from direct query (from SSMS or VS).
Posted
Updated 4-Nov-15 20:36pm
v2

1 solution

There is an overhead to "data binding" and showing the rows in the UI.

To check this time the da.Fill(dt) only without the data binding to UI elements. (as a side DataSets and DataTables are also slower than direct queries because of the object structure).
 
Share this answer
 
Comments
Member 0123456789 5-Nov-15 4:55am    
Thanks you - it was simple solution at the end.
I've used System.Diagnostics.StopWatch and the connection and query execution with the table filling was taking under half a second, but the control rendering was taking sometimes more than 1-2 minutes. The DataGridViewControl, which I was copying from one place to another had the setting to autoresize each cell by its content. For the console rendering is taking around 1-3 seconds with StringBuilder.
Thanks you again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900