Solved

How to avoiding time out expired in VB 2008

Posted on 2011-03-23
15
523 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

919 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

12 Experts available now in Live!

Get 1:1 Help Now