大家知道,如果我写一个udl文件,就可以调出数据链接属性对话框
现在我要点一个按钮,就弹出该对话框,然后读出其中我选择的信息,组成一个数据库链接字符串,该如何做?
多谢大家回答。菜鸟非常感谢!

解决方案 »

  1.   

    没有人回答么?
    就是读到 数据链接属性对话框 里面设置的变量
    组成一个 数据库链接字符串
    csdn居然没有人会么?
      

  2.   

    #define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp.CreateInstance( __uuidof( riid ) );                                   if (FAILED(_hr)) _com_issue_error(_hr); }//
    inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
    inline void HandleComError(_com_error &e){
    _bstr_t bstrSource(e.Source());
    _bstr_t bs = _bstr_t(" 错误: ") + _bstr_t(e.Error()) 
           + _bstr_t("    ")
           + _bstr_t(" 消息: ") + _bstr_t(e.ErrorMessage()) 
                   + _bstr_t("    ")
       + _bstr_t(" 错误描述: ") + _bstr_t(e.Description());

    MessageBox(0,bs,bstrSource, MB_OK);
    //--------------------------------------------------------------CString CAdoDataModule::GetDBConnection()
    {

    CString strCnnString;
    HRESULT hr = S_OK;
    _ConnectionPtr m_pConnection;

    IDataSourceLocatorPtr dlPrompt = NULL;

    try
    {
    CREATEiNSTANCE(dlPrompt,DataLinks); // Prompt for connection information.
    m_pConnection = dlPrompt->PromptNew();

    // If connection object is NULL, user cancelled.
    if ( NULL == m_pConnection ) 
    return "";

    // Open connection (connection returned by DataLinks is just
    // a holder for the returned ConnectionString).
    TESTHR(hr = m_pConnection->Open( m_pConnection->ConnectionString, L"", L"", -1 ) ); 
    strCnnString =(char *) (m_pConnection->ConnectionString);
    return strCnnString;
    }
        catch( _com_error &e){
            HandleComError(e);
    // executing the query.
    if(m_pConnection != NULL)  m_pConnection.Release();
    return "";
    }

    }
      

  3.   

    http://dev.csdn.net/develop/article/21/21089.shtm