help help help

help help help

Post by amltbXlnbG » Sun, 04 Dec 2005 20:18:02


ello
i've been tryin for some hours now to solve this problem, and now my head is
spinning.....

i keep on gettin the same error (points to highligthed part down in code):

Unhandled exception at 0x0041168c in k.exe: 0xC0000005: Access violation
reading location 0x00000000.
First-chance exception at 0x0041168c in k.exe: 0xC0000005: Access violation
reading location 0x00000000.
Unhandled exception at 0x0041168c in k.exe: 0xC0000005: Access violation
reading location 0x00000000.


This is should be a simple example for accessin data, and executing TSQL
query... It's from some e-book i have, and it says there that it should
work... normally...although VC++ used there is i think 6th edition, and i'm
using VS 2005 professional....

concerning this error i understand what it means but i don't know how to fix
it...


Where stdafx.h is:

#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <tchar.h>
#define UNICODE
#define _UNICODE
#define DBINITCONSTANTS
#define INITGUID

// Standard Application Includes
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include <stddef.h>
#include <iostream>


// OLE DB Header Files
#include <oledb.h>
#include <oledberr.h>


// OLE DB - ODBC Provider Header Files
#include <msdaguid.h>
#include <msdasql.h>

CODE:

#include "stdafx.h"

void main() {

IDBInitialize* pIDBInitialize = NULL;
IDBCreateSession* pCreateSession = NULL;
IDBCreateCommand* pCreateCommand = NULL;
IRowset* pRowset = NULL;
ICommandText* pCommandText = NULL;
IDBProperties* pIDBProperties;
IColumnsInfo* pColumnsInfo;
IAccessor* pAccessor;
HACCESSOR hAccessor;
DBCOLUMNINFO* pDBColumnInfo;
DBPROP InitProperties[4];
DBPROPSET rgInitPropSet[1];
int i;
ULONG j,lNumCols,cbColOffset = 0;
ULONG lNumRowsRetrieved;
HROW hRows[5];
HROW* pRows = &hRows[0];
LONG cNumRows;
DBBINDING* pBindings;
char *pBuffer;
WCHAR* pStringsBuffer;

// The Command to execute
LPCOLESTR wCmdString = OLESTR("SELECT pid, Name FROM Caller list");

// Initialize the Component Object Module Library
CoInitialize(NULL);

// Obtain Access to the OLE DB - ODBC Provider
CoCreateInstance(CLSID_MSDASQL, NULL,
CLSCTX_INPROC_SERVER,IID_IDBInitialize, (void **) &pIDBInitialize);

// Initialize the property values that are the same for each
// property...
for (i = 0; i < 4; i++ ) {

VariantInit(&InitProperties.vValue);
InitProperties.dwOptions = DBPROPOPTIONS_REQUIRED;
InitProperties.colid = DB_NULLID;
}

// level of prompting that will be done to complete the
// connection process
InitProperties[0].dwPropertyID = DBPROP_INIT_PROMPT;
InitProperties[0].vValue.vt = VT_I2;
InitProperties[0].vValue.iVal = DBPROMPT_NOPROMPT;

// Specify the Username
InitProperties[1].dwPropertyID = DBPROP_AUTH_USERID;
InitProperties[1].vValue.vt = VT_BSTR;

// Note: The L cast directive casts the string into a UNICODE
// string....
InitProperties[1].vValue.bstrVal = SysAllocString((LPOLESTR)L"");

// Specify the appropriate Password
InitProperties[2].dwPropertyID = DBPROP_AUTH_PASSWORD;
InitProperties[2].vValue.vt = VT_BSTR;
InitProperties[2].vValue.bstrVal = SysAllocString((LPOLESTR)L"");

// Specify the Data Source name
InitProperties[3].dwPropertyID = DBPROP_INIT_DATASOURCE;
InitProperties[3].vValue.vt = VT_BSTR;
InitProperties[3].vValue.bstrVal = SysAllocString((LPOLESTR L"MyData