我在学MFC的ODBC数据库编程,书上说要在编程之前设置ODBC数据源,然后才能在VC里对数据库操作。如果我把做好的程序放在用户的机子上,那用户不是要重新设置数据源才能用我的程序?
还有一个问题,我想基于C/S开发数据库,安装了SQL SERVER 2000,可是客户端必须安装SQL的客户端,然后连接数据源,客户端程序才能访问数据库服务器呀。
    请问有哪位朋友知道如何将远程访问数据库全部集中在客户端程序中,不用在客户端建立数据源。我找了好多书,都是说要先建立数据源的。

解决方案 »

  1.   

    有API
    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.DiagnosticsWhen SQLConfigDataSource returns FALSE, an associated *pfErrorCode value may be obtained by calling SQLInstallerError. The following table lists the *pfErrorCode values that can be returned by SQLInstallerError and explains each one in the context of this function.*pfErrorCode Error Description 
    ODBC_ERROR_
    GENERAL_ERR General installer error An error occurred for which there was no specific installer error. 
    ODBC_ERROR_
    INVALID_HWND Invalid window handle The hwndParent argument was invalid or NULL. 
    ODBC_ERROR_
    INVALID_
    REQUEST_TYPE Invalid type of request The fRequest argument was not one of the following:
    ODBC_ADD_DSN
    ODBC_CONFIG_DSN
    ODBC_REMOVE_DSN
    ODBC_ADD_SYS_DSN
    ODBC_CONFIG_SYS_DSN
    ODBC_REMOVE_SYS_DSN
    ODBC_REMOVE_DEFAULT_DSN
     
    ODBC_ERROR_
    INVALID_NAME Invalid driver or translator name The lpszDriver argument was invalid. It could not be found in the registry. 
    ODBC_ERROR_
    INVALID_
    KEYWORD_
    VALUE Invalid keyword-value pairs The lpszAttributes argument contained a syntax error. 
    ODBC_ERROR_
    REQUEST_
    FAILED Request failed The installer could not perform the operation requested by the fRequest argument. The call to ConfigDSN failed. 
    ODBC_ERROR_
    LOAD_LIBRARY_
    FAILED Could not load the driver or translator setup library The driver setup library could not be loaded. 
    ODBC_ERROR_
    OUT_OF_MEM Out of memory The installer could not perform the function because of a lack of memory. 
    CommentsSQLConfigDataSource uses the value of lpszDriver to read the full path of the setup DLL for the driver from the system information. It loads the DLL and calls ConfigDSN with the same arguments that were passed to it.SQLConfigDataSource returns FALSE if it is unable to find or load the setup DLL, or if the user cancels the dialog box. Otherwise, it returns the status it received from ConfigDSN.SQLConfigDataSource maps the System DSN fRequests to the User DSN fRequests (ODBC_ADD_SYS_DSN to ODBC_ADD_DSN, ODBC_CONFIG_SYS_DSN to ODBC_CONFIG_DSN, and ODBC_REMOVE_SYS_DSN to ODBC_REMOVE_DSN). To distinguish user and System DSNs, SQLConfigDataSource sets the installer configuration mode according to the following table. Prior to returning, SQLConfigDataSource resets configuration mode to BOTHDSN.fRequest Configuration mode 
    ODBC_ADD_DSN USERDSN_ONLY 
    ODBC_CONFIG_DSN USERDSN_ONLY 
    ODBC_REMOVE_DSN USERDSN_ONLY 
    ODBC_ADD_SYS_DSN SYSTEMDSN_ONLY 
    ODBC_CONFIG_SYS_DSN SYSTEMDSN_ONLY 
    ODBC_REMOVE_SYS_DSN SYSTEMDSN_ONLY Related FunctionsFor information about See 
    Adding, modifying, or removing a data source ConfigDSN (in the setup DLL) 
    Removing a data source name from the system information SQLRemoveDSNFromIni 
    Adding a data source name to the system information SQLWriteDSNToIni