I've been developing some small database applications in Visual Studio C# for a while now. I am currently using VS 2010. Up until recently all the apps were ran on the same computer that the database was stored on and everything ran great. Recently I had to start to developing some apps that 开发者_JAVA百科will run on a separate computer that is on the same local network.
Easy enough, but I run into a problem when running queries to fill controls, such as a grid or even combo box. The problem is that it can take 15-30 seconds per control if my query is pulling a large amount of data. I know this is because the app is sending out my select query, waiting for all of the results to come across the network and then displaying the information. The problem is I don't know what to do about it.
Below I have a code snippet(slightly modified to make more sense). It is using a Firebird database, though I use MSSQL and Sybase Advantage as well with the same results.
FbConnection fdbConnect = new FbConnection();
fdbConnect.ConnectionString = Program.ConnectionString;
fdbConnect.Open();
FbCommand fcmdQuery = new FbCommand();
fcmdQuery.Connection = fdbConnect;
fcmdQuery.CommandText = "select dadda.name, yadda.address, yadda.phone1 from SOMETABLE left join yadda on dadda where yadda.pk = dadda.yaddapk";
FbDataAdapter fdaDataSet = new FbDataAdapter(fcmdQuery);
DataSet dsReturn = new DataSet();
fdaDataSet.Fill(dsReturn);
fdbConnect.Close();
DataGridView1.DataSource = dsReturn.Tables[0];
Does anyone have any suggestions on how I can speed this up?
You may returning unnecessary data in that SELECT * statement. It can be wasteful in network traffic and drive down the performance of your application. There are many articles about this and how you should specify your columns explicitly. Here is one in particular.
You can reduce the volume of the response by restricting your columns:
Instead of
select * from SOMETABLE
Try
select a,b,c from SOMETABLE
to retrieve only the data you need.
Your mileage vary depending on what the table contains. If there are unused blob columns for instance, you are adding a considerable overhead to your response.
If you are displaying the data in gridview
, and if data is huge, its better to do server side paging so that a specific number of rows is returned at a time.
精彩评论