如何建立动态数据源

解决方案 »

  1.   

    #include "stdafx.h"
    #include <windows.h>
    #include <odbcinst.h>
    #include <sqlext.h>
    #include <iostream.h>LPSTR   szDriver = "SQL Server";
    LPSTR   szAttributes = 
      "DSN=MyDSN\0DESCRIPTION=SQLConfigDSN Sample\0"
      "SERVER=MySQL\0ADDRESS=MyServer\0NETWORK=dbmssocn\0"
      "DATABASE=pubs\0";if( 
      SQLConfigDataSource(NULL, ODBC_ADD_DSN, szDriver, szAttributes) == FALSE ) {
        cout << "fail to call SQLConfigDataSource" << endl;
    }if( SQLConfigDataSource(NULL, ODBC_REMOVE_DSN, szDriver,  szAttributes) == FALSE ) {
    cout << "fail to call SQLConfigDataSource" << endl;
    } cout << "end of TestConfigDSN" << endl;