Solved

VB.net SQL Client slow

Posted on 2014-11-08
10
242 Views
Last Modified: 2014-11-14
Hi

I am using VB.net SQL Client to pull data on my local connection from a view that has 6 million records.
In the process I count the number of items in for instance a column called "Plant" that can contain only one of two
values "P01" and "P02". If I count the number of records that contain "P02" it times out. I tested it in SQL Server Management Studio and it took three minutes.
Is the technology the problem or is this something that might be caused by the speed at which my computer is running?
0
Comment
Question by:murbro
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40430880
If it returns total of P01" and "P02", and it is not grouped by, say "Plant", using a function call, you may want, to have total of "P01"s and then say total op "P02"s = Number or records in the tabale - "P01"s

But I don't it is this simple and there must be some category of some sort to group by. Just a thought.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40431273
This sound like a need to implement a index on the column "Plant" which should drastically increase the response time. I am not an SQL database Guru so I can't direct you in how to go about this implementing the index.

In answer to to your question, "Is the technology the problem or is this something that might be caused by the speed at which my computer is running?", well the technology is not the problem. The problem is that it sounds like the database table/view is poorly designed for what you need to do.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40431318
how do you count them? it should look like this:

select Plant, count(*) from YourTableName

Open in new window


I am not sure that creating an index would help in this case as you only have 2 values (not enough discriminating)
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40431330
Hi Eric;

Seeming that an index will segregate the values stored in the column, so all "P01" will be together and all "P02" will be together, and you want to query for only "P01" and lets say that "P01" is 1/4 of the 6 million records then it would only take 1/4 of the time to return the known "P01" records?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40431428
not in the case of a count where all the rows needs to be scanned
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40431433
Hi Eric;

In the question it states this, "If I count the number of records that contain "P02" it times out.", so are you saying that SQL server would not optimize the query plan to take into account the index of that column seeming you would not be counting all entries?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 40431435
would need to check the execution plan.
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40431474
murbro,

1. What the query looks like, are there other fields involved?

2. What is your connection string?

3. Paste the try catch with the rest of the code here. If no try catch, still paste the code for us to see.

Mike
0
 
LVL 47

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40432375
If I count the number of records that contain "P02" it times out. I tested it in SQL Server Management Studio and it took three minutes.
That's because in SSMS you don't have a timeout period set but you do in VS. You need to change the timeout period in the connection in VS (by default is 30 seconds).
Also as recommended here by Fernando Soto, an index on the column may help increase the performance of your query.
0
 

Author Closing Comment

by:murbro
ID: 40442676
thanks
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSIS with VPN COnnection 2 78
Find SQL query used by application 3 20
Unable to Uninstall Visual Studio 2015 7 27
SQL2016 to ORACLE11G linked-server 6 16
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question