i want to conncet to a ms sql server,but the debug info: "invalid pointer!"
is there any problems in my coding?
by debugging, i know the problem must lie in the variant strConnect.
i use ms sql server 2000+ winxp+ visual c++6.0
_ConnectionPtr m_pConnection ;
void ADOConn::OnInitADOConn()
{
::CoInitialize(NULL);
try
{
m_pConnection.CreateInstance("ADODB.Recordset");
_bstr_t strConnect="Provider=SQLOLEDB;
TRUSTED_CONNECTION=TRUE;//use windows log in
Initial Catalog=...../*database name*/;
Data Source=SJTU-3V87CA6SZP";//server name
m_pConnection->Open(strConnect,"","",adModeUnknown);
}
catch (_com_error e) {
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
TRACE( "Exception thrown for classes generated by #import" );
TRACE( "\tCode = %08lx\n", e.Error());
TRACE( "\tCode meaning = %s\n", e.ErrorMessage());
TRACE( "\tSource = %s\n", (LPCTSTR) bstrSource);
TRACE( "\tDescription = %s\n", (LPCTSTR) bstrDescription);
}
}OK, I think you forgot to add the Microsoft.ADODB to the project references list. Try that and let me know.
Sree|||do you mean i must add #import "c:\program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF") rename("BOF","adoBOF")??
i have added it to the .h file
if you refer to a different meaning, please tell me the meaning of "project reference list"
thank you very much!!
No comments:
Post a Comment