Solved

How to avoiding time out expired in VB 2008

Posted on 2011-03-23
15
514 Views
Last Modified: 2012-05-11
Today you send me a solution using BackgroundWorker and it worked, but in my routine there is a lot of stored procedures and in a certais time I received the messege below:
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

In adicction I have to say that in the begining I had only one procedure, but, because of this problem I divided  the procedure. In spite of this I can´t still avoid the time out.

Thanks for your help.
0
Comment
Question by:JGonzaga
  • 6
  • 6
15 Comments
 
LVL 4

Expert Comment

by:MaximumIQ
Comment Utility
you can add "Connect Timeout"  and value in seconds to your connection string.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.71).aspx
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 125 total points
Comment Utility
Did you try the above suggestion?
0
 

Author Comment

by:JGonzaga
Comment Utility
Yes I´ve tried it but sometimes the time out expired still occurs. Ono of the experts told me that the problem coud be in the data base. So i´ve done a new question about SQL database becouse I heven´t realized that the correct way to procced should be redirect this question  to another zones (i´m a beginner in EE) .

sorry, I think that is better close this question.



0
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 125 total points
Comment Utility
Trying using connectiontimeout in the connection string but also set the COMMANDTIMEOUT property of the SQLCOMMAND object to a bigger value

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx
0
 

Author Comment

by:JGonzaga
Comment Utility

where I do this? On the code or on the database configuration?
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
On the SqlCommand object that is being used to interact with the DB.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:JGonzaga
Comment Utility
Please could you be more specific?

I´m not a professional programer. I used to work with MSAcces and I´m just beginner with Vb 8 and MySql

I will be very grateful if you give the basic steps.

Thanks a lot.

 
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Show me the code you are using currently.
0
 

Author Comment

by:JGonzaga
Comment Utility
This is the code. Before the procedure I have problem I put a comment.

Thanks for your help.
If Mid(MTabela, 1, 4) = "SPF_" Then
                            Dim cmd As New MySqlCommand
                            Dim parametro As New MySqlParameter
                            parametro.ParameterName = "Parquivo"
                            parametro.Value = NumArquivo
                            Try
                                cmd.Connection = Conn
                                cmd.CommandType = CommandType.StoredProcedure
                                cmd.Parameters.Add(parametro)
                         
				' This procedures makes a lot of things in big tables and sometimes time out expired occurs
                                cmd.CommandText = "ProcGeraLivros"
                                cmd.ExecuteNonQuery()
                            Catch ex As Exception
                                MessageBox.Show("Erro ProcGeraLivros." & ex.Message, "Gera Livros")
                            End Try
                        Else
                            Dim cmd As New MySqlCommand
                            Dim parametro As New MySqlParameter
                            parametro.ParameterName = "PIndEsc"
                            parametro.Value = MIndEsc
                            Try
                                cmd.Connection = Conn
                                cmd.CommandType = CommandType.StoredProcedure
                                cmd.Parameters.Add(parametro)
                                cmd.CommandText = "ProcGeraPlanoContas"
                                cmd.ExecuteNonQuery()
                            Catch ex As Exception
                                MessageBox.Show("Erro ProcGeraPlanoContas." & ex.Message, "Gera Plano de contas")
                            End Try
                        End If

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Add the

cmd.CommandTimeOut = 32000

before ExecuteNonQuery()
0
 

Assisted Solution

by:JGonzaga
JGonzaga earned 0 total points
Comment Utility
Thanks. I´ll try this.
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Why did not you just accept an answer?
0
 

Author Closing Comment

by:JGonzaga
Comment Utility
It was a great solution. I´m very greateful
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now