473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to correct SqlConnection.Timeout value?

4
Hi, i got a bug on a C# application, the problem is that i have a static class to manage all transactions with a database, and the application should try for itself to connect to defined SQL Server IP's. Everything is fine except that when i try to connect to any of the IP's the timeout specified in the Connection string is ignored, instead takes the default value (30 secs) and this is a pain. If the app can´t connect to any of the specified IPs then ask the user for the IP and makes another attempt to connect, this time using an overloaded function that takes the IP addr as parameter, and the weird is that in this attempt the Timeout works as specified in the connection string. Anyone has an idea about how to solve this?

Expand|Select|Wrap|Line Numbers
  1. foreach (string IP in SQL_IPs)
  2.             {
  3.                 string ConnectionString = CSPart1 + IP + CSPart2;
  4.                 try
  5.                 {
  6.                     SQLCon = new SqlConnection(ConnectionString);
  7.  
  8.                     SQLCon.Open();
  9.                     if (SQLCon.State == ConnectionState.Open)
  10.                     {
  11.                         BuildArrays();
  12.                         return true;
  13.                     }
  14.                 }
  15.                 catch (SqlException sqlex)
  16.                 {
  17.                     Console.WriteLine("===========================================");
  18.                     Console.WriteLine(sqlex.Message);
  19.                     Console.WriteLine(sqlex.StackTrace);
  20.                     Console.WriteLine(sqlex.Source);
  21.                     Console.WriteLine("===========================================");
  22.                     continue;
  23.                 }
  24.             }
  25.             return false;
ConnectionString Used:
Expand|Select|Wrap|Line Numbers
  1. Initial Catalog=DB1; Data Source=172.16.1.5;User ID=admin; Password=admin; Connection Timeout=3
Thanks in advance
Jun 16 '10 #1
2 2902
ThatThatGuy
449 Expert 256MB
Initial Catalog=DB1; Data Source=172.16.1.5;User ID=admin; Password=admin; Connection Timeout=3
The keyword is Timeout and not Connection Timeout

and you cannot specify timeout as 3 as it can be specified in milliseconds
Jun 17 '10 #2
JSan
4
Thanks for the answer, but i found a workaround using a thread then join the thread in less of a specified timeout, because i was trying to control the TCP timeout (if one of the servers is down try the next) Thanks anyway
Jun 17 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Robert Oschler | last post by:
I want to change the time it takes the browser to timeout before producing a 404 error on one of my web pages. I want to do it before I set the SRC attribute of an IFRAME on the page, and change...
1
by: Ahmet AKGUN | last post by:
Hi All; I have one server to which clients are connected to via TcpChannel. I start server on one host and establish a client connection from another host via tcpchannel. On client, using...
2
by: Cheung Wang Tin | last post by:
How can I set in web.config, so that session is enable, but never timeout? Thank you.
0
by: fish | last post by:
Hi, There is no property to read the timeout from FormsAuthenticationModule or FormsAuthentication class. How do I get the timeout value from the following web.config ? .... ...
4
by: A.M-SG | last post by:
Hi, How can I increase the HTTP Timeout value at the client side? Thank you, Alan
7
by: ad | last post by:
The default of timeout value of session is 20 min. How can I change the value in program?
2
by: Jamie Schatte | last post by:
Hi, I have an ASP.NET 2.0 website that uses SQL Server session state. All works well with session state, except it seems like no matter what value I use for the timeout in web.config, the session...
2
by: Jarf | last post by:
I have and ASP.Net 2.0 application I've set the session state to use SQL Server and I modified the Timeout setting to be 60 minutes. However, my session is still expiring in 20 minutes. Looking in...
2
by: ken | last post by:
Can you please tell me what is the timeout value of httplib.HTTP? i.e. how long python will wait for a response in the below code? h = httplib.HTTP(self.url, 8080) h.putrequest('GET',...
13
by: =?Utf-8?B?ZG91Zw==?= | last post by:
I support several intranet sites one of which had NO STATE. Even though content has ASP extensions, it was all rendered HTML. Site had NO session or application variables being managed. Site had...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.