Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,
in my application i need to connect to about 50 databases and copy some data but while connecting my application got stuck in between on any database while opening connection for hours till i terminate it even after giving connection timeout

C#
foreach (DataRow row in dt.Rows)
 {
    try
      {
//first i am pinging the IP if it replies then i am proceeding
         System.Net.NetworkInformation.Ping objping = new System.Net.NetworkInformation.Ping();
         if (objping.Send(row["FTP_IP"].ToString()).Status == System.Net.NetworkInformation.IPStatus.Success)
 {
                            
     constr = @"Data Source=10.**.**.**/orcl;User                      ID=*****;Password=****;ConnectionLifetime=60;Connection Timeout=30;Timeout=30;";
                            store_con = new OracleConnection(constr);  
// i tried this using thread but its not working                          
                            //Thread workerThread = new Thread(DoWork);
                            //workerThread.Start();
                            //Thread.Sleep(5000);
                            //workerThread.Join();
                            store_con.Open();//here its getting stuck no error nothing 


so is there any other way to overcome this situation like using thread or backgroundworker
i want it should try only for 5 seconds at max.
i don't want the thread to wait for 5 seconds for every connection...because most of them got connected within 1 or 2 seconds
Posted
Updated 15-Sep-14 20:56pm
v5
Comments
Nathan Minier 15-Sep-14 8:27am    
Interesting fact, read the note in the documentation for OracleConnection:
http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracleconnection.connectiontimeout%28v=vs.110%29.aspx

"Unlike the Connection object in the other .NET Framework data providers (SQL Server, OLE DB, and ODBC), OracleConnection does not support a ConnectionTimeout property. Setting a connection time-out either with a property or in the connection string has no effect, and the value returned is always zero."

Oh, and it's deprecated.
Basmeh Awad 16-Sep-14 2:47am    
thanks, so is their any other logic like using thread or backgroundworker?
Nathan Minier 16-Sep-14 8:25am    
My advice, due to it's deprecated nature, is to follow Microsoft's guidance and use a different namespace. Oracle has a .NET provider with it's own wonderful flair, I'm sure. Try using its classes instead.

http://www.oracle.com/technetwork/topics/dotnet/index-085163.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900