Solved

How to avoiding time out expired in VB 2008

Posted on 2011-03-23
15
531 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
ID: 35200478
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
ID: 35306470
Did you try the above suggestion?
0
 

Author Comment

by:JGonzaga
ID: 35306528
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 125 total points
ID: 35306564
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
ID: 35306684

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

Expert Comment

by:CodeCruiser
ID: 35306693
On the SqlCommand object that is being used to interact with the DB.
0
 

Author Comment

by:JGonzaga
ID: 35306771
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
ID: 35309680
Show me the code you are using currently.
0
 

Author Comment

by:JGonzaga
ID: 35314045
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
ID: 35314071
Add the

cmd.CommandTimeOut = 32000

before ExecuteNonQuery()
0
 

Assisted Solution

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

Expert Comment

by:CodeCruiser
ID: 35315435
Why did not you just accept an answer?
0
 

Author Closing Comment

by:JGonzaga
ID: 35356856
It was a great solution. I´m very greateful
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

15 Experts available now in Live!

Get 1:1 Help Now