SQLConfigDataSource这个函数
ConformanceVersion Introduced: ODBC 1.0SummarySQLConfigDataSource adds, modifies, or deletes data sources.SyntaxBOOL SQLConfigDataSource(
   HWND   hwndParent,
   WORD   fRequest,
   LPCSTR   lpszDriver,
   LPCSTR   lpszAttributes);ArgumentshwndParent[Input]
Parent window handle. The function will not display any dialog boxes if the handle is null.fRequest[Input]
Type of request. fRequest must contain one of the following values:ODBC_ADD_DSN: Add a new user data source.ODBC_CONFIG_DSN: Configure (modify) an existing user data source.ODBC_REMOVE_DSN: Remove an existing user data source.ODBC_ADD_SYS_DSN: Add a new system data source.ODBC_CONFIG_SYS_DSN: Modify an existing system data source.ODBC_REMOVE_SYS_DSN: Remove an existing system data source.ODBC_REMOVE_DEFAULT_DSN: Remove the default data source specification section from the system information. It also removes the default driver specification section from the ODBCINST.INI entry in the system information. (This fRequest performs the same function as the deprecated SQLRemoveDefaultDataSource function.) When this option is specified, all of the other parameters in the call to SQLConfigDataSource should be NULLs; if they are not NULL, they will be ignored.lpszDriver[Input]
Driver description (usually the name of the associated DBMS) presented to users instead of the physical driver name.lpszAttributes[Input]
List of attributes in the form of keyword-value pairs. For more information, see ConfigDSN in Chapter 22, “Setup DLL Function Reference.”ReturnsThe function returns TRUE if it is successful, FALSE if it fails. If no entry exists in the system information when this function is called, the function returns FALSE.

解决方案 »

  1.   

    //创建方法
    if(SQLConfigDataSource(m_pMainWnd->m_hWnd,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)",
    "DSN=Personnel\0"
    "DBQ=C:\\My Documents\\dq.mdb\0"
    "DefaultDir=C:\\My Documents\0"
    "Driver={Microsoft Access Driver (*.mdb)}\0"
    "DriverId=790\0"
    "Deleted=1\0"
    "Description=描述性文本\0"
    "FileType=Access\0"
    "JetIniPath=odbcddp.ini\0"
    "MaxScanRows=20\0"
    "MaxBufferSize=512"
    "ImplicitCommitSync=No\0"
    "UserCommitSync=No\0"
    "Exclusive=1\0"//独占
    "ReadOnly=1\0"//只读
    "UID=Smith\0"
    "SafeTransactions=0\0"
    "PWD=Sesame\0"
    "DATABASE=dq\0"
    "ExtendedAnsiSQL=1\0"
    "Statistics=0\0"
    "\0"))
    AfxMessageBox("创建成功!");
    else
    AfxMessageBox("取消创建或创建失败!");
    //删除数据源
    SQLConfigDataSource(NULL,ODBC_REMOVE_DSN,"Microsoft Access Driver (*.mdb)","DSN=数据库名称\0\0");