OpenEx vs. Open 
Author Message
 OpenEx vs. Open

I have a question concerning the use of CDatabase::OpenEx vs ::Open.

The situation that started my current dilema , was this:

I had a SQLServer data source setup that pointed at an invalid database.  I
have an application that attempts to use this data source to connect to the
DB.  This application is a NT service that normally has no interaction with
the desktop.

When the application attempted to open the DB connection using the ::Open
function, the ODBC API call ::SQLDriverConnect was attempting to get more
info by popping up the data source diaglog.

There did not seem to be anyway to tell Open not to have that happen.

So I switched to OpenEx.

Now the dialog is not being displayed, but the call to OpenEx is returning
TRUE.   How can this be, when I know that the data source being used points
at an invalid DB?

When the ODBC dialog was displayed and I chose Cancel, the Open function
properly failed.

How do I get OpenEx to report back the failure to connect?
If I attempt to use the connection as is, I get failure.

Any thoughts or help would be greatly appreciated.

If additional details would help, let me know.

Either post
 or e-mail me at:

Thanks,

Rick Barnes



Sat, 16 Sep 2000 03:00:00 GMT  
 OpenEx vs. Open

In theory, the behavior of Open and OpenEx should be the same. The
documentation says the following about the return value for both of the
functions.

"Nonzero if the connection is successfully made; otherwise 0 if the user
chooses Cancel when presented a dialog box asking for more connection
information. In all other cases, the framework throws an exception."

My interpretation of this based on what you are saying is that the only time
the functions will return 0 is if a user selects the Cancel button, even if
the connection fails. Are you catching CDBException properly?

I'm guessing that this is probably a bug/design flaw. I don't remember if
the problem was with either of these functions specifically, but, in the
past I have noticed similar behavior where I expected the function to either
return an error or throw and exception, but, it didn't.

I would try stepping through the code in debug mode. If the problem appears
to be with the MFC wrapper around the ODBC API calls, you can create your
own CDatabase derived class and override Open/OpenEx so that it behaves the
way that you want it to. e.g. you could have it call ::SQLConnect instead of
::SQLDriverConnect.

Jon

Quote:

>I have a question concerning the use of CDatabase::OpenEx vs ::Open.

>The situation that started my current dilema , was this:

>I had a SQLServer data source setup that pointed at an invalid database.  I
>have an application that attempts to use this data source to connect to the
>DB.  This application is a NT service that normally has no interaction with
>the desktop.

>When the application attempted to open the DB connection using the ::Open
>function, the ODBC API call ::SQLDriverConnect was attempting to get more
>info by popping up the data source diaglog.

>There did not seem to be anyway to tell Open not to have that happen.

>So I switched to OpenEx.

>Now the dialog is not being displayed, but the call to OpenEx is returning
>TRUE.   How can this be, when I know that the data source being used points
>at an invalid DB?

>When the ODBC dialog was displayed and I chose Cancel, the Open function
>properly failed.

>How do I get OpenEx to report back the failure to connect?
>If I attempt to use the connection as is, I get failure.

>Any thoughts or help would be greatly appreciated.

>If additional details would help, let me know.

>Either post
> or e-mail me at:

>Thanks,

>Rick Barnes



Sun, 17 Sep 2000 03:00:00 GMT  
 OpenEx vs. Open

The OpenEx throws an exception if the connection failed. Catch the
exception.

Harish

Quote:

>I have a question concerning the use of CDatabase::OpenEx vs ::Open.

>The situation that started my current dilema , was this:

>I had a SQLServer data source setup that pointed at an invalid database.  I
>have an application that attempts to use this data source to connect to the
>DB.  This application is a NT service that normally has no interaction with
>the desktop.

>When the application attempted to open the DB connection using the ::Open
>function, the ODBC API call ::SQLDriverConnect was attempting to get more
>info by popping up the data source diaglog.

>There did not seem to be anyway to tell Open not to have that happen.

>So I switched to OpenEx.

>Now the dialog is not being displayed, but the call to OpenEx is returning
>TRUE.   How can this be, when I know that the data source being used points
>at an invalid DB?

>When the ODBC dialog was displayed and I chose Cancel, the Open function
>properly failed.

>How do I get OpenEx to report back the failure to connect?
>If I attempt to use the connection as is, I get failure.

>Any thoughts or help would be greatly appreciated.

>If additional details would help, let me know.

>Either post
> or e-mail me at:

>Thanks,

>Rick Barnes



Sun, 17 Sep 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. OpenDatabase, OpenEx,Open

2. CDatabase::Open & OpenEx

3. CRecordset, Open == OpenEx ??

4. CRecordset, Open == OpenEx ??

5. CRecordset, Open == OpenEx ??

6. Unable to open ODBC file dsn using OpenEx method

7. CDatabase::OpenEX vs CDatabase::openExclusive option

8. fopen vs. open

9. Open GL on VS.NET

10. open vs. fopen - file locking fcntl

11. open vs fopen

12. fopen vs. open

 

 
Powered by phpBB® Forum Software