Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    1

    Unanswered: Problem with connecting to database programmatically

    Hi,
    I'm trying to set up a database connectivity programatically. I'm using VC++ .Net and trying to set up a ODBC connection to MS Access. This is the code am using to accomplish this, but I'm getting a few error messages. Could anyone of you kindly help me with this. Thanks

    BOOL SQLConfigDataSource(NULL,ODBC_CONFIG_DSN,
    (LPSTR) "Microsoft Access Driver(*.mdb)",
    (LPSTR) "DSN= Access Data Source\0"
    "Description= Access Data Source\0"
    "FileType=MS Access\0"
    "DataDirectory=C:\\test1\0");

    and these are the errors I'm getting.

    error C2065: 'ODBC_CONFIG_DSN' : undeclared identifier
    error C2078: too many initializers
    error C2440: 'initializing' : cannot convert from 'char *' to 'BOOL'

    Thank You.

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: Problem with connecting to database programmatically

    Originally posted by karthikrg
    Hi,
    I'm trying to set up a database connectivity programatically. I'm using VC++ .Net and trying to set up a ODBC connection to MS Access. This is the code am using to accomplish this, but I'm getting a few error messages. Could anyone of you kindly help me with this. Thanks

    BOOL SQLConfigDataSource(NULL,ODBC_CONFIG_DSN,
    (LPSTR) "Microsoft Access Driver(*.mdb)",
    (LPSTR) "DSN= Access Data Source\0"
    "Description= Access Data Source\0"
    "FileType=MS Access\0"
    "DataDirectory=C:\\test1\0");

    and these are the errors I'm getting.

    error C2065: 'ODBC_CONFIG_DSN' : undeclared identifier
    error C2078: too many initializers
    error C2440: 'initializing' : cannot convert from 'char *' to 'BOOL'

    Thank You.
    Outside of the obvious: (VBA Forum)

    When you use a DSN, that is all you put in the connection string execpt for any optional user and password authentications. Ex:

    DSN=MyDSN;User=Admin;PWD=SomePassword;

  3. #3
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Ok ...

    This is some of my code in VC++ using a DSN in ADO ...

    Code:
    /****************************************************************************/
    /**  ROUTINE NAME: CCatalogNTDlg::OpenTheDatabase                           */
    /**  DESCRIPTION : Open the Access Database.                                */
    /**  PARAMETERS  : NONE                                                     */
    /**  RETURN VALUE: TRUE - Successfully opened the Access Database.          */
    /**                                                                         */
    /**  NOTES       :                                                          */
    /****************************************************************************/
    BOOL CCatalogNTDlg::OpenTheDatabase()
    	{
    //	_bstr_t	PVMDriver = "DSN=CatalogNT;";
    //	_bstr_t DBUser = "UID=Admin;";
    //	_bstr_t	DBPassword = "PREfix";// "PWD=PREfix;"
    
    	try
    		{
    		::CoInitialize(NULL);
    #ifdef _DEBUG
    		ASSERT(SUCCEEDED(AccessConn.CreateInstance(__uuidof(Connection))));
    #else
    		AccessConn.CreateInstance(__uuidof(Connection));
    #endif
    //		PVMConn->Open("DBQ=c:\\pvmnt\\db\\ver.70\\portfolio.939.mdb;""Driver=Microsoft Access Driver (*.mdb);","","",-1);
    		AccessConn->Open("DSN=CatalogNT;","","",-1);
    		DatabaseIsOpen = true;
    		}
    	catch( _com_error e )
    		{
    		::MessageBox(0,(LPCTSTR)e.Description(),e.ErrorMessage(),MB_OK);
    		DatabaseIsOpen = false;
    		return FALSE;
    		}
    	return TRUE;
    	}
    I hope this can help you out ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •