Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

LoadNetlibs exception

Sometimes the following exception occured when I Open a connection to an SQL server from a COM+ application:

<2001/08/02 18:26:58> COM EXCEPTION!
  File = f:\projects\qnet\qnetlib\sql7db.cpp
  Line = 65
  Mess = Connection object - Open. DSN: 'Provider=SQLOLEDB;Data Source=.;Initial Catalog=QNetDBWork'
  Code = 80004005
  Code meaning = Unspecified error
  Source = Microsoft OLE DB Provider for SQL Server
  Description = [DBNETLIB][ConnectionOpen (LoadNetlibs()).]

The sql7db.cpp lines (line 65 is the DUMP_EXCEPTION line).

CString dsn;
dsn.Format ("Provider=SQLOLEDB;Data Source=.;Initial Catalog=%s",database);
BSTR bdsn=dsn.AllocSysString ();
CString coms; coms.Format("Connection object - Open. DSN: '%s'",dsn);
try
{
  conn->Open (bdsn,(char *)(LPCSTR)user,(char *)(LPCSTR)password,0);
}
catch (_com_error &e)
{
DUMP_EXCEPTION((char *)(LPCSTR)coms,e);
::SysFreeString (bdsn);
conn_ok=FALSE;
}


What can be the problem ?
0
stewe
Asked:
stewe
1 Solution
 
jkrCommented:
How are 'user' and 'password' declared? If they're CStrings, the line should read

 conn->Open (bdsn,(LPCTSTR)user,LPCTSTR)password,0);
0
 
steweAuthor Commented:
Open needs LPCTSTR ? Not char * ?
Can it be a prob ?
0
 
jkrCommented:
>>Open needs LPCTSTR ?

It takes char*, but 'CString::operator LPCTSTR()' is the one that actually converts a 'Cstring' into a char. By using '(char *)(LPCSTR)user', you're misusing a CString as a pointer - try it...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
steweAuthor Commented:
I use the (char *)(LPCSTR) in my code many times.
There were no errors about it...
0
 
jkrCommented:
>>I use the (char *)(LPCSTR) in my code many times.

That's not correct, even though you didn't have any errors (so far).

Hmm, did you try it for this case?
0
 
steweAuthor Commented:

I haven't received that error yet (after modifying to LPCTSTR). But I'm debugging and trying. Later I'll write what happened.
But of course I'll see this question's comments.

  Stewe
0
 
griesshCommented:
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "jkr" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
ComTechCommented:
After review, the proposed answer will be accepted by:

ComTech
Community Support Admin
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now