PC Review


Reply
Thread Tools Rate Thread

Connection timeout set to 5 sec but takes longer to timeout

 
 
Avi
Guest
Posts: n/a
 
      9th Mar 2010
Hi all,



My Connection string timeout was set to 5 sec but commands takes much longer
to timeout when there is no connection to the destination ip. Is the
timeout value only helps when the ip is reachable but the sql server is not,
or it should work also if the ip address is unreachable. If it should work
also when the ip is unreachable, why it does not work in my case?

Thanks a million,

Avi

public static int ExecCommand(string command, string ip)

{

if (String.IsNullOrEmpty(ip))

throw new ManualRedundancyException("IP address for database connection
cannot be null");

string connectionStr = "Data Source=" + ip + ";Initial
Catalog=master;Persist Security Info=True;User
ID=sa;Password=1210;Connection Timeout=5;";

using (SqlConnection cn = new SqlConnection(connectionStr))

{

using (SqlCommand cm = new SqlCommand(command, cn))

{

cn.Open();

int i = cm.ExecuteNonQuery();

return i;

}

}

}


 
Reply With Quote
 
 
 
 
sloan
Guest
Posts: n/a
 
      9th Mar 2010

There is a Connection Timeout AND a separate Command Timeout.

http://msdn.microsoft.com/en-us/libr...ndtimeout.aspx

http://msdn.microsoft.com/en-us/libr...ontimeout.aspx

Make sure you're dealing with the correct one.



"Avi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
>
>
>
> My Connection string timeout was set to 5 sec but commands takes much
> longer to timeout when there is no connection to the destination ip. Is
> the timeout value only helps when the ip is reachable but the sql server
> is not, or it should work also if the ip address is unreachable. If it
> should work also when the ip is unreachable, why it does not work in my
> case?
>
> Thanks a million,
>
> Avi
>
> public static int ExecCommand(string command, string ip)
>
> {
>
> if (String.IsNullOrEmpty(ip))
>
> throw new ManualRedundancyException("IP address for database connection
> cannot be null");
>
> string connectionStr = "Data Source=" + ip + ";Initial
> Catalog=master;Persist Security Info=True;User
> ID=sa;Password=1210;Connection Timeout=5;";
>
> using (SqlConnection cn = new SqlConnection(connectionStr))
>
> {
>
> using (SqlCommand cm = new SqlCommand(command, cn))
>
> {
>
> cn.Open();
>
> int i = cm.ExecuteNonQuery();
>
> return i;
>
> }
>
> }
>
> }
>
>



 
Reply With Quote
 
Avi
Guest
Posts: n/a
 
      10th Mar 2010
Thanks for the reply.

I'm only talking to the connection timeout. Event when I set the timeout in
the connection string to 5 seconds it will take much longer to get timeout
if the IP address in unreachable.

Avi


"sloan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> There is a Connection Timeout AND a separate Command Timeout.
>
> http://msdn.microsoft.com/en-us/libr...ndtimeout.aspx
>
> http://msdn.microsoft.com/en-us/libr...ontimeout.aspx
>
> Make sure you're dealing with the correct one.
>
>
>
> "Avi" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi all,
>>
>>
>>
>> My Connection string timeout was set to 5 sec but commands takes much
>> longer to timeout when there is no connection to the destination ip. Is
>> the timeout value only helps when the ip is reachable but the sql server
>> is not, or it should work also if the ip address is unreachable. If it
>> should work also when the ip is unreachable, why it does not work in my
>> case?
>>
>> Thanks a million,
>>
>> Avi
>>
>> public static int ExecCommand(string command, string ip)
>>
>> {
>>
>> if (String.IsNullOrEmpty(ip))
>>
>> throw new ManualRedundancyException("IP address for database connection
>> cannot be null");
>>
>> string connectionStr = "Data Source=" + ip + ";Initial
>> Catalog=master;Persist Security Info=True;User
>> ID=sa;Password=1210;Connection Timeout=5;";
>>
>> using (SqlConnection cn = new SqlConnection(connectionStr))
>>
>> {
>>
>> using (SqlCommand cm = new SqlCommand(command, cn))
>>
>> {
>>
>> cn.Open();
>>
>> int i = cm.ExecuteNonQuery();
>>
>> return i;
>>
>> }
>>
>> }
>>
>> }
>>
>>

>
>



 
Reply With Quote
 
Patrice
Guest
Posts: n/a
 
      10th Mar 2010
If I remember a similar thread you have a limit anyway under which you can't
go.

How much time does it take now ? If I remember you can't go between 10/15 s.
If still higher it could be perhaps another problem (name resolution being
slow ?)

--
Patrice

"Avi" <(E-Mail Removed)> a écrit dans le message de groupe de
discussion : e#(E-Mail Removed)...
> Thanks for the reply.
>
> I'm only talking to the connection timeout. Event when I set the timeout
> in the connection string to 5 seconds it will take much longer to get
> timeout if the IP address in unreachable.
>
> Avi
>
>
> "sloan" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>
>> There is a Connection Timeout AND a separate Command Timeout.
>>
>> http://msdn.microsoft.com/en-us/libr...ndtimeout.aspx
>>
>> http://msdn.microsoft.com/en-us/libr...ontimeout.aspx
>>
>> Make sure you're dealing with the correct one.
>>
>>
>>
>> "Avi" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi all,
>>>
>>>
>>>
>>> My Connection string timeout was set to 5 sec but commands takes much
>>> longer to timeout when there is no connection to the destination ip. Is
>>> the timeout value only helps when the ip is reachable but the sql server
>>> is not, or it should work also if the ip address is unreachable. If it
>>> should work also when the ip is unreachable, why it does not work in my
>>> case?
>>>
>>> Thanks a million,
>>>
>>> Avi
>>>
>>> public static int ExecCommand(string command, string ip)
>>>
>>> {
>>>
>>> if (String.IsNullOrEmpty(ip))
>>>
>>> throw new ManualRedundancyException("IP address for database connection
>>> cannot be null");
>>>
>>> string connectionStr = "Data Source=" + ip + ";Initial
>>> Catalog=master;Persist Security Info=True;User
>>> ID=sa;Password=1210;Connection Timeout=5;";
>>>
>>> using (SqlConnection cn = new SqlConnection(connectionStr))
>>>
>>> {
>>>
>>> using (SqlCommand cm = new SqlCommand(command, cn))
>>>
>>> {
>>>
>>> cn.Open();
>>>
>>> int i = cm.ExecuteNonQuery();
>>>
>>> return i;
>>>
>>> }
>>>
>>> }
>>>
>>> }
>>>
>>>

>>
>>

>
>
>


 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      10th Mar 2010
http://www.connectionstrings.com/sql-server-2005
Connect via an IP address

If you try it with the "most anal" connection string....

where you specify the
IPAddress
Port
Protocol ("Network Library" in the above URL)

(And don't forget to throw in the Connection Timeout as well (as you are
doing in your original sample).
Connection Timeout=30";

Which behavior does it exhibit?


..................

And have you verified the connection string value is being written?
(This is a long shot I realize......but better safe than sorry)


using (SqlConnection cn = new SqlConnection(connectionStr))
{
Console.WriteLine("Just making super sure : " +
Convert.ToString(cn.ConnectionTimeout); // << What are you getting here?
//your other code
}


"Avi" <(E-Mail Removed)> wrote in message
news:e%(E-Mail Removed)...
> Thanks for the reply.
>
> I'm only talking to the connection timeout. Event when I set the timeout
> in the connection string to 5 seconds it will take much longer to get
> timeout if the IP address in unreachable.
>
> Avi
>
>
> "sloan" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>
>> There is a Connection Timeout AND a separate Command Timeout.
>>
>> http://msdn.microsoft.com/en-us/libr...ndtimeout.aspx
>>
>> http://msdn.microsoft.com/en-us/libr...ontimeout.aspx
>>
>> Make sure you're dealing with the correct one.
>>
>>
>>
>> "Avi" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi all,
>>>
>>>
>>>
>>> My Connection string timeout was set to 5 sec but commands takes much
>>> longer to timeout when there is no connection to the destination ip. Is
>>> the timeout value only helps when the ip is reachable but the sql server
>>> is not, or it should work also if the ip address is unreachable. If it
>>> should work also when the ip is unreachable, why it does not work in my
>>> case?
>>>
>>> Thanks a million,
>>>
>>> Avi
>>>
>>> public static int ExecCommand(string command, string ip)
>>>
>>> {
>>>
>>> if (String.IsNullOrEmpty(ip))
>>>
>>> throw new ManualRedundancyException("IP address for database connection
>>> cannot be null");
>>>
>>> string connectionStr = "Data Source=" + ip + ";Initial
>>> Catalog=master;Persist Security Info=True;User
>>> ID=sa;Password=1210;Connection Timeout=5;";
>>>
>>> using (SqlConnection cn = new SqlConnection(connectionStr))
>>>
>>> {
>>>
>>> using (SqlCommand cm = new SqlCommand(command, cn))
>>>
>>> {
>>>
>>> cn.Open();
>>>
>>> int i = cm.ExecuteNonQuery();
>>>
>>> return i;
>>>
>>> }
>>>
>>> }
>>>
>>> }
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: Timeout expired. The timeout period elapsed prior to comple michael Microsoft ADO .NET 3 22nd Feb 2009 06:05 PM
IIS Timeout , Web Config Timeout, Page Timeout. =?Utf-8?B?TWlrZSBNb29yZQ==?= Microsoft Dot NET 0 17th Jan 2006 06:52 PM
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. Guoqi Zheng Microsoft ASP .NET 4 3rd Jun 2004 07:39 PM
Timeout expired. The timeout period elapsed prior to completion of the operation Manoj K Microsoft VB .NET 1 4th Jan 2004 08:47 AM
another "InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool" error Jeff Braun Microsoft ADO .NET 1 30th Jul 2003 12:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:45 AM.