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 ?
LVL 1
steweAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
jkrConnect With a Mentor Commented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.