V
Vital_Parsley
Guest
I will just show a step by step process of how i m goin about the database application i m creating.
Problem i m facing is i m not able to create an instance of Connection ,as it is returning a value FAILED.
1) Created a SDI with FormView as base class and name MFCADO.
2) In CMFCADOApp InitInstance() added the line AfxOleInit() to initialise COM.
3) Made changes to StdAfx.h by adding the following code at the end of the file.Which is shown in grey color font.(Dont know exactly where to add this code in the file ??????)
#include <comdef.h>
#import "C:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename( "EOF", "adoEOF" )
4) Added 2 variabled in MFCADODoc
public:
BOOL m_IsConnectionOpen;
_ConnectionPtr m_pConnection;
initialized m_pConnection =FALSE in MFCADODoc constructor.
5) Added the below code to MFCADODoc::OnNewDocument( )
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance( __uuidof( Connection ) ); // RETURNS FAILED AS the next If condition is not executed.
if (SUCCEEDED(hr))
{
AfxMessageBox("You are now Connected!",NULL,MB_OK); //Not Executed
hr = m_pConnection->Open(_bstr_t(L"Provider=sqloledb;Data Source=C:\\Program Files\\Microsoft SQL Server\\MSSQL\\Data\\LibDB;"), _bstr_t(L""), _bstr_t(L""), adModeUnknown);
if (SUCCEEDED(hr))
{
m_IsConnectionOpen = TRUE;
}
}
else if(FAILED(hr))
AfxMessageBox("Not able to connect to DB!",NULL,MB_OK); //Executed
}
catch( _com_error &e )
{
// Get info from _com_error
_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);
}
catch(...)
{
TRACE( "*** Unhandled Exception ***" );
}
I do not know what i have done wrong in this process. ??????????
I would be grateful if some1 could rectify and mistakes and tell me to how to make changes to the above codes. !!!!!!!!!!!
6) I have a Ok button on my form which when clicked takes a single record and displays them in the respective edit boxes.But for that i need to get hr=SUCCEEDED!!
value of hr is -858993460 as seen in the watch window.
Continue reading...
Problem i m facing is i m not able to create an instance of Connection ,as it is returning a value FAILED.
1) Created a SDI with FormView as base class and name MFCADO.
2) In CMFCADOApp InitInstance() added the line AfxOleInit() to initialise COM.
3) Made changes to StdAfx.h by adding the following code at the end of the file.Which is shown in grey color font.(Dont know exactly where to add this code in the file ??????)
#include <comdef.h>
#import "C:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename( "EOF", "adoEOF" )
4) Added 2 variabled in MFCADODoc
public:
BOOL m_IsConnectionOpen;
_ConnectionPtr m_pConnection;
initialized m_pConnection =FALSE in MFCADODoc constructor.
5) Added the below code to MFCADODoc::OnNewDocument( )
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance( __uuidof( Connection ) ); // RETURNS FAILED AS the next If condition is not executed.
if (SUCCEEDED(hr))
{
AfxMessageBox("You are now Connected!",NULL,MB_OK); //Not Executed
hr = m_pConnection->Open(_bstr_t(L"Provider=sqloledb;Data Source=C:\\Program Files\\Microsoft SQL Server\\MSSQL\\Data\\LibDB;"), _bstr_t(L""), _bstr_t(L""), adModeUnknown);
if (SUCCEEDED(hr))
{
m_IsConnectionOpen = TRUE;
}
}
else if(FAILED(hr))
AfxMessageBox("Not able to connect to DB!",NULL,MB_OK); //Executed
}
catch( _com_error &e )
{
// Get info from _com_error
_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);
}
catch(...)
{
TRACE( "*** Unhandled Exception ***" );
}
I do not know what i have done wrong in this process. ??????????
I would be grateful if some1 could rectify and mistakes and tell me to how to make changes to the above codes. !!!!!!!!!!!
6) I have a Ok button on my form which when clicked takes a single record and displays them in the respective edit boxes.But for that i need to get hr=SUCCEEDED!!
value of hr is -858993460 as seen in the watch window.
Continue reading...