Wrox Programmer Forums
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2003, 04:50 PM
Authorized User
 
Join Date: Nov 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default OdbcException

Hi

I'm trying to get an OdbcException when I execute a query
with a closed connection but I only get a normal exception
my code is:

try {
string query = "Select * from users";
OdbcCommand cmm = new OdbcCommand(query,conn);
object result = cmm.ExecuteScalar();
}
catch(OdbcException Ex1)
  MessageBox.show(Ex1.Message);
catch(Exception Ex2)
  MessageBox.show(Ex2.Message);

Then I guess that I get an OdbcException if my connection
is closed but I get an normal Exception.

Whats is wrong???

Regards



 
Old January 22nd, 2004, 10:55 AM
Registered User
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When you try to run ExecuteSclar method on the command object without opening associated connection, you will be getting exception of type
System.InvalidOperationException. The same generic exception class is raised when you use SQLClient or ODBC namespaces.So use this class and catch the error.










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.