Database connectivity with Objective Grid
Microsoft Access
The Objective Grid distribution includes Microsoft Access .mdb files for testing data binding with ODBC and ADO in the samples built with Win32.
Enabling ODBC Source on x64
On an x64 machine, you have to use the 32-bit version of ODBC Data Source Administrator, located at C:\Windows\SysWOW64\odbcad32.exe, to set the data sources.
Microsoft SQL Server
The Grid samples for both Win32 and x64 provide for connectivity to SQL Server. To test the ODBC samples, you need to set the data source with an available SQL Server driver. We recommend installation of Microsoft's standard sample database, Northwind.
To test the ADO samples, download and install SQL Server x64 drivers on the test machine. You may obtain Microsoft's SQL Server updates from http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ceb4346f-657f-4d28-83f5-aae0c5c83d52.
For testing ADO with SQL Server, you can override CreateRecordSet in the Grid sample ADOQuery as follows:
In adoquvw.h, add the following function prototype:
 
CComPtr<ADORecordset> CreateRecordset(CComBSTR bstrSource,CComBSTR bstrSQL);
In adoquvw.cpp, add the following function implementation:
 
CComPtr<ADORecordset> CAdoqueryView::CreateRecordset(CComBSTR bstrSource,
CComBSTR bstrSQL)
{
bstrSource = "Provider=SQLNCLI10; Data Source=<data source name>;
InitialCatalog=Northwind; User Id=<user ID>; Password=<password>";
return CMyAdoRecordView:: CreateRecordset(bstrSource, bstrSQL);
}
When using the sample Northwind database, use the "Select* from Customers" query.
Oracle
For testing ODBC samples built with Win32, set DSN with Microsoft ODBC for Oracle. To test ADO samples from an x86 machine, be sure msdaora.dll is installed. There are two options available: connection through ODBC or directly.
1. Use following connection string to connect to ODBC through ADO:
 
bstrSource = "Driver={Microsoft ODBC for Oracle};
DSN = <data source name>; Uid=<user ID>; Pwd=<password>";
2. For a direct connection through ADO, use the following connection string:
 
bstrSource = "Provider=msdaora; Data Source=<data source name>;
User Id=<user ID>; Password=<password>";
Then, use the following override:
 
CComPtr<ADORecordset> CAdoqueryView::CreateRecordset(CComBSTR bstrSource,
CComBSTR bstrSQL)
{
HRESULT hr;
COleVariant vNull;
CComPtr<ADORecordset> piRecordSet;
CComPtr<ADOConnection> piConnection;
//Select a source
bstrSource = "Driver={Microsoft ODBC for Oracle}; DSN = OraTest;
Uid=dbtest1;Pwd=zebco5";
//bstrSource = "Provider=msdaora; Data Source=kettle; User Id=dbtest1;
Password=zebco5";
hr = CoInitialize(NULL);
if (FAILED(hr))
{
AfxMessageBox(_T("Unable to Initialize COM"));
goto ErrorExit;
}
 
//Intialize Connection
hr = CoCreateInstance(CLSID_CADOConnection, NULL, CLSCTX_INPROC_SERVER,
IID_IADOConnection, (LPVOID *)&piConnection);
if(FAILED(hr))
{
AfxMessageBox(_T("Unable to create connection object"));
goto ErrorExit;
}
 
if ( bstrSource == NULL || bstrSQL == NULL )
{
AfxMessageBox(_T("Invalid(NULL) Source name or SQL string"));
goto ErrorExit;
}
 
//Initialize Recordset
hr = CoCreateInstance(CLSID_CADORecordset, NULL, CLSCTX_INPROC_SERVER,
IID_IADORecordset, (LPVOID *)&piRecordSet);
if(FAILED(hr))
{
AfxMessageBox(_T("Unable to create Recordset"));
goto ErrorExit;
}
BOOL bSuccess;
hr = piConnection->Open( bstrSource, NULL, NULL, -1 );
if (FAILED(hr))
{
AfxMessageBox(_T("Unable to make connection to Source: ")
+CString(bstrSource));
goto ErrorExit;
}
hr = piRecordSet->putref_ActiveConnection(piConnection);
if (FAILED(hr))
{
AfxMessageBox(_T("Unable to bind Connection/Recordset"));
goto ErrorExit;
}
hr = piRecordSet->put_Source(bstrSQL);
if (FAILED(hr))
{
AfxMessageBox(_T("Unable to put_Source"));
goto ErrorExit;
}
 
// If your provider does not have cursor capabilities set,
// use put_CursorLocation(adUseClient) on the recordset before
// calling Open to make ADO use the cursor library from the
// service components: piRecordSet->put_CursorLocation(adUseClient);
// This is necessary for Oracle
vNull.vt = VT_ERROR;
vNull.scode = DISP_E_PARAMNOTFOUND;
GX_ADO_CHECK(piRecordSet->Open(vNull, vNull, adOpenKeyset,
adLockOptimistic, adCmdText),piRecordSet,bSuccess)
if(!bSuccess)
{
goto ErrorExit;
}
 
return piRecordSet;
ErrorExit: TCHAR szBuf[256]; wsprintf(szBuf, _T("Error: %d \n"), hr);
if (hr) AfxMessageBox(szBuf); CoUninitialize();
return NULL;
}
Re-Enabling DAO in Objective Grid
Although Stingray Studio dropped support for DAO when that support was dropped by Microsoft, the DAO code was not dropped from the code base. So you can still use DAO by making the Objective Grid Build Wizard aware of this code. For information on how to do this, please see this article in the Stingray Forums: http://forums.roguewave.com/showthread.php?136-Enabling-DAO-in-OG-10.4.