try...catch newbie, please help 
Author Message
 try...catch newbie, please help

I'm a newbie w/ try - catch statments.  I'm calling a service that returns an sda, which i use for my datasource.  The service makes the connection to one data source and if it can't connect, it does a catch & connects to a backup db.  I know that my try...catch is NOT correct because it never goes into the catch, and I'm purposely making the line that creates the new sda fail (to test it out).  Here's the code in the page where i call the service:
--------        
        DataSet ds = new DataSet();                            
        OleDbDataAdapter sda;  

        Service1 mytest = new Service1();     // i instantiate my service here - works fine
        sda = mytest.get_erpwip(strBldgid);   // call webmethod, pass arg for Select statemnt  

        sda.SelectCommand.Connection.Open();  // this fails, the sda isn't the right one
        sda.Fill(ds, "Erpwip");
--------                

I get an oleDB exception error on the Open() above.  The webmethod code for the service is here, and this is where something is wrong & i really need the help w/ the try-catch:
---------
        public OleDbDataAdapter get_erpwip(String bldgid)
        {
          OleDbConnection con  = new OleDbConnection();
          con.ConnectionString = "Provider=....; Data Source=RRRR";          

          OleDbDataAdapter sda;
          try   {                      
                sda = new OleDbDataAdapter("SELECT yada yada", con);
                return(sda);

          }
          catch(Exception e) {

                con.ConnectionString = "Provider=.....; Data Source=PROP";            
                sda = new OleDbDataAdapter("SELECT yada yada", con);
                return(sda);
          }
        }
---------

Jason Shohet  212-863-6481  
(phone may still be down due to cowardly attack at WTC)

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Sun, 14 Mar 2004 11:19:17 GMT  
 try...catch newbie, please help

i figured this out.  Apparently i need to do  con.Open()  for it to throw an exception.  Just creating a new sda and passing it back from a service isn't enough, the try never fails.  I've got to open the connection, and if that opening fails, it goes to the catch.  

God Bless America
Jay

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 14 Mar 2004 20:19:19 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. TRY-CATCH vs. try-catch

2. try/catch VS TRY/CATCH

3. newbie Q: debugging try/catch

4. Newbie question on try ... catch in ATL

5. newbie try throw and catch question

6. newbie Simple Try Catch question

7. Can you catch CDBExection with try-catch keyword?

8. why {try catch} does not catch

9. Q: Why try catch cannot catch the exception

10. HELP ??try and catch

11. HELP! Basic Try/Catch problem

12. Help on C++ try/catch/finally

 

 
Powered by phpBB® Forum Software