Configure ODBC Data Source WITHOUT Using ODBC Administrator

Configure ODBC Data Source WITHOUT Using ODBC Administrator

Post by Yi Fan » Thu, 28 Nov 1996 04:00:00



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

 
 
 

Configure ODBC Data Source WITHOUT Using ODBC Administrator

Post by Matt Woodwar » Thu, 28 Nov 1996 04:00:00


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


 
 
 

Configure ODBC Data Source WITHOUT Using ODBC Administrator

Post by Peter Gucw » Sat, 30 Nov 1996 04:00:00



> 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:}

 
 
 

1. Data Source: Programmatically Configuring an ODBC Data Source - HELP PLEASE

OP: WIN95
COMPILER: VCPP 5.0 (SVP 2)

I have the above code, and I don't know why the "OPTION 1" does not work.
The contents of "p" in memory is the same as 2nd and 3rd line of the "OPTION
2" before the SQLConfigDataSource function.
Thanks, for any help.

char *p = new char[100];
char cCnt = 0;
memset(p,NULL,100);
CString strDummy = "DNS=TESTESQL";

for(char i=0;i<strDummy.GetLength();i++)
     p[cCnt++] = strDummy.GetAt(i);

p[cCnt++] = NULL;

strDummy = "DBQ=C:\\Projetos\\SRO_CPQD\\SOFTWARE\\PRS
TESTE\\PRS\\MDB\\sro.mdb";

for(i=0;i<strDummy.GetLength();i++)
     p[cCnt++] = strDummy.GetAt(i);
p[cCnt++] = NULL;
BOOL bRet = FALSE;
// ***** OPTION 1 *****
bRet = SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver
(*.mdb)",p);

// ***** OPTION 2 *****
bRet = SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver
(*.mdb)",
        "DSN=TESTESQL\0"
        "DBQ=C:\\Projetos\\SRO_CPQD\\SOFTWARE\\PRS
TESTE\\PRS\\MDB\\sro.mdb\0");


2. ODBC driver error

3. access to odbc without configuring locally the source ?

4. Help with difficult TIME dimension situation

5. Error while configuring ODBC data Source

6. Choosing DBMS: friendly to Linux, Apache, Perl, Java

7. Cannot configure Oracle ODBC data source

8. Close objects

9. Configure ODBC driver's and data source's from command line

10. How to create and configure ADO/ODBC Data Source programmatically for MS Acces

11. configure ODBC data source programmatically

12. Connecting via ODBC without a data source

13. JDBC and MS Access without ODBC data source