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;
>>>
>>> }
>>>
>>> }
>>>
>>> }
>>>
>>>
>>
>>
>
>