Configure ODBC Data Source WITHOUT Using ODBC Administrator 
Author Message
 Configure ODBC Data Source WITHOUT Using ODBC Administrator

Hi, There:
I have an ODBC issue and appreciate any
suggestions and comments.

My application needs to access to the Microsoft
Access-based data sources (.MDB files). I am
now able to configure and connect them to my
application by using ODBC Administrator.  However,
I really like have my application take care this
config and connect because All .MDB files are
provided by END USERS. I prefer not have end users
been bothered on ODBC Administrator. Therefore, the  
Questions are:

1. Can the config and connect work currently done
by MS ODBC Administrator BE accomplished by
applications ( using VC++ or so)?

2. If can, what statement(in VC++) can be used?

Suppose that all the .MDB file Names are given.

Thanks in advance.

Yi Fang



Sun, 16 May 1999 03:00:00 GMT  
 Configure ODBC Data Source WITHOUT Using ODBC Administrator

I think you'll find SQLCreateDataSource to do what you need.  If you use
ODBC 3.0, SQLCreateDataSource runs a wizard that prompts the user
step-by-step for the information they need to create data sources.  It
allows creation of user, system as well as file data sources.

SQLDriverConnect in ODBC 3.0 also presents a "New" button from which a user
can create a new data source.

For complete information, please see the ODBC 3.0 SDK documentation which
is available on http://www.microsoft.com/odbc

I hope this helps!

Matt Woodward
--
The opinions expressed in this message are my own personal views
and do not reflect the official views of Microsoft Corporation



Quote:
> Hi, There:
> I have an ODBC issue and appreciate any
> suggestions and comments.

> My application needs to access to the Microsoft
> Access-based data sources (.MDB files). I am
> now able to configure and connect them to my
> application by using ODBC Administrator.  However,
> I really like have my application take care this
> config and connect because All .MDB files are
> provided by END USERS. I prefer not have end users
> been bothered on ODBC Administrator. Therefore, the  
> Questions are:

> 1. Can the config and connect work currently done
> by MS ODBC Administrator BE accomplished by
> applications ( using VC++ or so)?

> 2. If can, what statement(in VC++) can be used?

> Suppose that all the .MDB file Names are given.

> Thanks in advance.

> Yi Fang



Sun, 16 May 1999 03:00:00 GMT  
 Configure ODBC Data Source WITHOUT Using ODBC Administrator

Quote:

> 1. Can the config and connect work currently done
> by MS ODBC Administrator BE accomplished by
> applications ( using VC++ or so)?

Yes

Quote:
> 2. If can, what statement(in VC++) can be used?

Below is code which I use. This code is based on
template of the ODBC driver in M$'s ODBC SDK.
Function updates ODBC.INI in Windows 3.1 and
M$'s Registry in Windows95

/* SetDSNAttributes
--------------------------------------------------------
  Description:  Write data source attributes to ODBC.INI
  Input      :  hwnd - Parent window handle (plus globals)
  Output     :  TRUE if successful, FALSE otherwise
--------------------------------------------------------------------------*/
BOOL INTFUNC SetDSNAttributes(HWND hwndParent, LPSETUPDLG lpsetupdlg)
{
        LPCSTR  lpszDSN;                                                // Pointer to data source name

        lpszDSN = lpsetupdlg->aAttr[KEY_DSN].szAttr;

        // Validate arguments
        if (lpsetupdlg->fNewDSN && !*lpsetupdlg->aAttr[KEY_DSN].szAttr)
                return FALSE;

        // Write the data source name
        if (!SQLWriteDSNToIni(lpszDSN, lpsetupdlg->lpszDrvr))
        {
                if (hwndParent)
                {
                        char  szBuf[MAXPATHLEN];
                        char  szMsg[MAXPATHLEN];

                        LoadString(s_hModule, IDS_BADDSN, szBuf, sizeof(szBuf));
                        wsprintf(szMsg, szBuf, lpszDSN);
                        LoadString(s_hModule, IDS_MSGTITLE, szBuf, sizeof(szBuf));
                        MessageBox(hwndParent, szMsg, szBuf, MB_ICONEXCLAMATION | MB_OK);
                }
                return FALSE;
        }

        // Update ODBC.INI
        // Save the value if the data source is new, if it was edited, or if
        // it was explicitly supplied
        if (hwndParent || lpsetupdlg->aAttr[KEY_DESC].fSupplied )
                SQLWritePrivateProfileString(lpszDSN,
                        INI_KDESC,
                        lpsetupdlg->aAttr[KEY_DESC].szAttr,
                        ODBC_INI);

        if (hwndParent || lpsetupdlg->aAttr[KEY_SERVERDSN].fSupplied )
                SQLWritePrivateProfileString(lpszDSN,
                        INI_KSERVERDSN,
                        lpsetupdlg->aAttr[KEY_SERVERDSN].szAttr,
                        ODBC_INI);

        if (hwndParent || lpsetupdlg->aAttr[KEY_DSADDRESS].fSupplied )
                SQLWritePrivateProfileString(lpszDSN,
                        INI_KDSADDRESS,
                        lpsetupdlg->aAttr[KEY_DSADDRESS].szAttr,
                        ODBC_INI);

        if (hwndParent || lpsetupdlg->aAttr[KEY_DBQ].fSupplied )
                SQLWritePrivateProfileString(lpszDSN,
                        INI_KDBQ,
                        lpsetupdlg->aAttr[KEY_DBQ].szAttr,
                        ODBC_INI);

        // If the data source name has changed, remove the old name
        if (lpsetupdlg->aAttr[KEY_DSN].fSupplied &&
                lstrcmpi(lpsetupdlg->szDSN, lpsetupdlg->aAttr[KEY_DSN].szAttr))
        {
                SQLRemoveDSNFromIni(lpsetupdlg->szDSN);
        }
        return TRUE;

Quote:
}



Tue, 18 May 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using ODBC to Configure Data Sources

2. Problems with ODBC MS Access Data source

3. C5EE - Importing ODBC Data Sources

4. ODBC Data Sources dialog usage in Clarion App

5. connecting to an odbc data source via clarion dictionary

6. Access ODBC data source via Clipper

7. HELP! Multiple ODBC data sources

8. ODBC to Oracle (data source name not found)

9. Setting up an ODBC data source

10. Using Fields Containing Binary Data with ODBC

11. Help using ODBC.pyd to retrieve ntext data from SQL server

12. Need ODBC or (better yet) OLE DB data driver/provider for CA-Realia ISAM data

 

 
Powered by phpBB® Forum Software