Re: ODBC connection strings - "ODBC;" prefix?
- From: r norman <r_s_norman@xxxxxxxxxxxx>
- Date: Mon, 12 Mar 2007 17:48:43 -0400
In summary, the official Microsoft position is that the strange
behavior that causes the operation to fail when applied seemingly
according to all the rules is " a by design behavior for upward
compatibility and should not be a bug".
On Mon, 12 Mar 2007 10:40:23 -0400, "Dave Calkins"
<david.calkins@xxxxxxxxxxxxxxx> wrote:
Thanks for your response. It sounds like CDatabase::Open() is working
correctly by removing the "ODBC;" if present and that CDatabase::OpenEx() is
not working correctly since it does not remove that.
Secondly, I don't think you're understanding what I'm saying. I am NOT
adding "ODBC;" to the string. MFC is doing that for me. You're talking
about it as though I'm adding it.
MFC is adding the "ODBC;" in the call I referenced in my prior reply. And
when I call CDatabase::OpenEx() it is not removing it.
So, I guess the way to go is to use Open() not OpenEx(). I'll proceed with
that. However, usually when there's a method and an Ex method, you're
supposed to use the Ex (I thought). I think OpenEx should also remove the
"ODBC;" if present. Just my $0.02.
Thanks,
Dave
"Charles Wang[MSFT]" <changliw@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:BcTFJKLZHHA.4088@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi, David,
Thanks for your response.
From my test, I found that this issue should be caused by SQLDriverConnect
which does not accept "ODBC;" parameters. If you observe CDatabase::Open
method, you will find that:
if (_tcsnicmp(strConnect, _afxODBCTrail, lstrlen(_afxODBCTrail)) == 0)
{
// Strip "ODBC;"
strConnect = strConnect.Right(strConnect.GetLength()
- lstrlen(_afxODBCTrail));
}
As you can see, if there is "ODBC;" in the connection string,
CDatabase::Open method will remove it; however, CDatabase::OpenEx does not
provide this function. When you add "ODBC;" to the connection string, for
instance "ODBC;DSN=MySQL2000;Database=GT;", the parameter pszConnectInput
value of ::SQLDriverConnect method will be "DSN=MySQL2000;Database=GT;"
for
CDatabase::Open method; while "ODBC;DSN=MySQL2000;Database=GT;" for
CDatabase::OpenEx.
The value with "ODBC;" will fail the driver connection. You can refer to
the nResult value.
Although MFC pre-pending the "ODBC;" after the SQLDriverConnect method, it
is just for saving the OUTPUT connection string and let us know that this
is an ODBC connection. This shoud be a by design behavior for upward
compatibility and should not be a bug.
Anyway, if you use OpenEx method, there is no need to use "ODBC;" which
will cause driver connection failure. Actually there is also no need to
use
"ODBC;" in the Open method now since it will be removed even if you add
the
"ODBC;" in the connection string. Also, you can see that OpenEx is called
at the end of the Open method.
Appreciate your understanding on this. If you have any other questions or
concerns, please feel free to let me know.
Have a good day!
Charles Wang
Microsoft Online Community Support
=====================================================
Get notification to my posts through email? Please refer to:
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications
If you are using Outlook Express, please make sure you clear the check box
"Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
======================================================
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
======================================================
.
- References:
- Re: ODBC connection strings - "ODBC;" prefix?
- From: Dave Calkins
- Re: ODBC connection strings - "ODBC;" prefix?
- From: Charles Wang[MSFT]
- Re: ODBC connection strings - "ODBC;" prefix?
- From: Dave Calkins
- Re: ODBC connection strings - "ODBC;" prefix?
- From: Charles Wang[MSFT]
- Re: ODBC connection strings - "ODBC;" prefix?
- From: Dave Calkins
- Re: ODBC connection strings - "ODBC;" prefix?
- Prev by Date: Re: ODBC connection strings - "ODBC;" prefix?
- Next by Date: Re: ODBC connection strings - "ODBC;" prefix?
- Previous by thread: Re: ODBC connection strings - "ODBC;" prefix?
- Next by thread: Re: ODBC connection strings - "ODBC;" prefix?
- Index(es):
Relevant Pages
|