Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to fire an error with CommandTimeout ?

Status
Not open for further replies.

vilrbn

Programmer
Oct 29, 2002
105
FR
Hello,

I dynamically build a DB2 query. I want to stop the request to the Database if it takes more than 5 minutes to get back a result.
I tried to add a Timeout on the connection and on the command, with no success. It's never poping up an error and I don't know how to do this.

Here is my code:

Try
cn = New OdbcConnection(ConfigurationSettings.AppSettings("Conndb2"))
cn.ConnectionTimeout = 1
Dim mystring As String = sbSelect.ToString & sbFrom.ToString & sbWhere.ToString
Dim cmd As OdbcCommand = New OdbcCommand(mystring)
cmd.CommandType = CommandType.Text
cmd.CommandTimeout = 1
cn.Open()

Dim da As New OdbcDataAdapter(mystring, cn)
da.Fill(ds, "office")
ListBox.DataSource = ds
ListBox.DataBind()
Catch exc As Exception
lblMsg.Text = &quot;<SCRIPT language = 'javascript'>alert('Error: &quot; & &quot;\n\n&quot; & exc.Message & &quot;');</SCRIPT>&quot;
Finally
cn.Close()
End Try

Can you help me ?
 
Is there a timout setting/default timeout for the connection string held in 'ConfigurationSettings.AppSettings(&quot;Conndb2&quot;)'. I know that for SQL Server connections there is a timeout setting here as well as for the SqlCommand, so I imagine your hitting this also.

Rhys

Be careful that the light at the end of the tunnel isn't a train coming the other way.
 
My connection string is define as follows:

<add key=&quot;ConnDB2&quot; value=&quot;Dsn=DB2P;Uid=Login;Pwd=Pwd&quot;/>

I perhaps have to had a parameter to fire the time out. I have to investigate as I do not really know the DB2 connection string syntax.

Thanks for your help.
 
My SQL Server connection string is;
&quot;data source=wdnnnnnn; initial catalog=CRA; uid=Compliance; pwd=asecret;Connect Timeout=1200&quot;

I'd say, initially at least, just try adding the 'Connect Timeout=n' setting to the end of the string...



Rhys

Be careful that the light at the end of the tunnel isn't a train coming the other way.
 
I tried but it has no effect. I also searched on many sites but didn't find any solution.
Thanks anyway !
 
You're probably never reaching the timeout limit then I'd suggest, or you should get an error returned.

Have you tried stepping thru the code one line at a time?

Rhys

Be careful that the light at the end of the tunnel isn't a train coming the other way.
 
I set the Timeout of the connection and the command to 1 second. It never pops up an error.
And if I step into the code line after line, I'm stuck if it's a complex query at that line:

da.Fill(ds, &quot;office&quot;) as I can have millions of records in the dataset

after a while, I'm getting a &quot;server application unavailable&quot; as the Web timeout has been reached.
Where can I change this value ? in the web.config ?
 
In the Internet Services Manager for IIS in Windows.

go to IIS, and right click on the web app in question from the tree view, selecting the 'properties' option.
Click the configuration button on the directory tab, and you should see an App options tab, which has values for the Web Timeout.


Rhys

Be careful that the light at the end of the tunnel isn't a train coming the other way.
 
Hello,

I tried to change those parameters and set them to 1.

Session timeout: 1 minute
ASP Script timeout: 1 minute

but it has no effect.

I saw others threads having the same problem as me. They solve it by adding a timeout in the connection string.
Unfortunately they are all using SQL and in my case, it's DB2 and I don't know its damn connection string parameters and syntax.

Thanks for your help !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top