Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Time out in a SQL Query VB.NET

Posted on 2011-09-17
8
Medium Priority
?
329 Views
Last Modified: 2012-05-12
Hi all,

Im getting the following message when updating records on a SQL Server:

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

The code is very simple:

Dim cadena2 As String = "update available_mills set status=1 where id=99 and location=@f3"
Dim cmd2 As New SqlCommand(cadena2, con2)
cmd2.CommandType = CommandType.Text
cmd2.Parameters.AddWithValue("@f3", F3)
cmd2.ExecuteNonQuery()

This updates about 4000 records every hour

Thanks!
0
Comment
Question by:pvg1975
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 36554544
set connection timeout to max

con2.timeout=0 this will be no time out
0
 

Author Comment

by:pvg1975
ID: 36554559
Im getting

Error      1      'timeout' is not a member of 'System.Data.SqlClient.SqlConnection'.

When using con2.timeout=0
0
 

Author Comment

by:pvg1975
ID: 36554589
I used this:

con2.CreateCommand.CommandTimeout = 0

And it seems to work. Am I doing it right? or createcommand is for something else?

Thanks!
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 15

Accepted Solution

by:
Haris Djulic earned 1000 total points
ID: 36554755
it is beter to use the timeout with the command since:

SqlCommand.CommandTimeout = timeout limit for your SQL query. Means, how much time a (eg: SELECT, UPDATE) query can take for its execution. If it exceeds SqlCommand.CommandTimeout, then it stops execution. A command timeout error will occur.

SqlConnection.ConnectionTimeout = timeout limit for your connection. Means, how much time your connection object can try to connect. If it exceeds the specified time, it stops connecting. A connection timeout error will occur.

you can use it like that

cmd2.CommandTimeout =0
0
 

Author Comment

by:pvg1975
ID: 36554888
Thanks, i tried it but i get an error. I will paste the error once im back home. Thanks.
0
 
LVL 7

Expert Comment

by:Kishan Zunjare
ID: 36555928
A sqlConnection has a ConnectionTimeout property. It  is a property which determines the maximum number of seconds your code will wait for a connection to the database to open. It is set in the connectionstring to the database

data source=BROCHIS;initial catalog=Indato;integrated security=SSPI;Connect Timeout=60;

Opening the connection does not do anything in the database yet. That is handled by a SqlCommand, By default this is 30 seconds. When you perform something costly in the database this is the one whose value you’ll have to change.

SqlCommand cmd;

cmd.CommandTimeout = 60;

Hope this will work...
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 1000 total points
ID: 36556778
There is simply no reason to increase the CommandTimeout (let alone set it to 0-Infinte) for such a simple UPDATE.  All you need to do is optimize your query.

Do you have an index on id, location?
0
 

Author Closing Comment

by:pvg1975
ID: 36556815
That worked perfect. I also optimized the table and added an index to the ID field. Thanks guys!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

670 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