how to connect Access database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I was using the following classes to get data from. Now I would like to know
which class shall I use from Windows Forms VC++ 2005.

CDaoDatabase m_Dao;
// Variables in String Table
// m_file = "C:\\Program Files\\Onair\\InVer.mdb"
// m_upass = "password"
m_Dao.Open(m_file ,FALSE, FALSE, m_upass);

CDaoRecordset m_Set;

COleVariant m_varprofile;
COleVariant m_varsection;

m_Set.GetFieldValue ("Profile", m_varprofile);

etc..,
 
I've read the msdn documents, & the samples works but the sample is created
to prompt for the link. When I modify the connection string as follows it
gives an error.

is it the right way or not...

IDataSourceLocatorPtr dlPrompt =
("Provider=Microsoft.Jet.OLEDB.4.0;Password=1234;User ID=Admin;Data
Source=Visu.mdb;");

& once connected do i have to use like this
_RecordsetPtr rs = NULL;
 
¤ I've read the msdn documents, & the samples works but the sample is created
¤ to prompt for the link. When I modify the connection string as follows it
¤ gives an error.
¤
¤ is it the right way or not...
¤
¤ IDataSourceLocatorPtr dlPrompt =
¤ ("Provider=Microsoft.Jet.OLEDB.4.0;Password=1234;User ID=Admin;Data
¤ Source=Visu.mdb;");
¤
¤ & once connected do i have to use like this
¤ _RecordsetPtr rs = NULL;
¤

Could you identify the error and the line of code on which it occurs?


Paul
~~~~
Microsoft MVP (Visual Basic)
 
the error code :-
error C2664: 'ado::Connection15::PutConnectionString' : cannot convert
parameter 1 from 'System::String __gc *' to '_bstr_t'

error line:-
conn->ConnectionString
=S"Provider=Microsoft.Jet.OLEDB.4.0;UserID=Admin;Password=1234;Data
Source=visu.mdb";

etc.,


this is how the code is Visual C++ .Net 2003
#include "stdafx.h"
#include <stdio.h>

#undef EOF
#import "c:\program files\common files\system\ole db\oledb32.dll"
rename_namespace("dlinks")
#import "c:\program files\common files\system\ado\msado15.dll"
rename_namespace("ado")

void TestConnection(void);

#ifdef _UNICODE
int wmain(void)
#else
int main(void)
#endif
{
TestConnection();
return 0;
}

void TestConnection(void)
{
using namespace dlinks;
using namespace ado;
using namespace System;

HRESULT hr;
::CoInitialize( NULL );

IDataSourceLocatorPtr dlPrompt = NULL;
hr = dlPrompt.CreateInstance(__uuidof(DataLinks));

_ConnectionPtr conn = NULL;

conn->ConnectionString
=S"Provider=Microsoft.Jet.OLEDB.4.0;UserID=Admin;Password=1235698;Data
Source=visu.mdb";
 
¤ the error code :-
¤ error C2664: 'ado::Connection15::PutConnectionString' : cannot convert
¤ parameter 1 from 'System::String __gc *' to '_bstr_t'
¤
¤ error line:-
¤ conn->ConnectionString
¤ =S"Provider=Microsoft.Jet.OLEDB.4.0;UserID=Admin;Password=1234;Data
¤ Source=visu.mdb";

The connection string looks OK, although you probably need to specify the System Database if you're
using user level security. Below is a connection string examples:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:System
Database=system.mdw;User Id=admin;Password=;"

You should be able to use the C++ OLEDB Data Provider example at:

http://support.microsoft.com/default.aspx?scid=kb;en-us;310071


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top