代码如下:
    _CatalogPtr m_pCatalog = NULL;
    _ConnectionPtr m_pConnection = NULL;
    try
    {
       m_pConnection.CreateInstance(__uuidof(Connection));
       m_pConnection->Open("Driver=SQL    Server;Database=TestDB;Server=XSERVER;UID=VIP;PWD=;","","",NULL);
       m_pCatalog.CreateInstance(__uuidof(Catalog));
       m_pCatalog->PutActiveConnection(variant_t((IDispatch *)  m_pConnection));
       m_pCatalog->Tables->Delete("TestTable");    }
     catch(_com_error &e)
    {
        _bstr_t bstrSource(e.Source());
        _bstr_t bstrDescription(e.Description());
        printf("\n\tSource :  %s \n\tdescription : %s \n ",
            (LPCSTR)bstrSource,(LPCSTR)bstrDescription);
    }

解决方案 »

  1.   

    我是采用SQL语句来删除的
    我也搞不懂为何m_pCatalog->Tables->Delete("TestTable");不成功
    反正能达到目的就行.
      

  2.   

    你的用户在SQL Server中有删除权限吗?
      

  3.   

    我的用户有删除权限,我以前是用SQL语句做删除工作的,但是如果在已有表中添加字段的话,由于不同的数据库它的数据类型不一样,比如说长二进制类型在ACCESS是OLE类型,但在SQLSERVER中是IMAGE类型。所以用SQL语句无法达到在不同的数据库中都适用的目的。
      

  4.   

    BOOL CJBaseSet::OpenDB()
    {
    BOOL bResult;
    HRESULT hr;
    CString strConn;#ifdef JETDB_ACCESS
    // CString str=JETDB_MDBFILE;
    strConn.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s",
    m_strDatabase);
    /*
    strConn.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;User ID=%s;PWD=%s",
    m_strDatabase,
    m_strUser,
    m_strPassword);
    */
    #else // SQL SERVER
    strConn.Format("Provider=SQLOLEDB;Password=%s;Persist Security Info=True;User ID=%s;Initial Catalog=%s;Data Source=%s",
    m_strPassword,
    m_strUser,
    m_strDatabase,
    m_strServer);
    #endif if((m_pConnection!=NULL)&&(m_pConnection->State))
    {
    m_pConnection->Close();
    //m_pConnection->Release();
    }
    //m_pConnection=NULL; bResult = FALSE;
    try
    {
    hr = m_pConnection.CreateInstance(__uuidof(Connection));
    if(SUCCEEDED(hr))
    {
    hr = m_pConnection->Open(_bstr_t(strConn),"","",-1);
    if(SUCCEEDED(hr))
    {
    bResult = TRUE;
    }
    else
    {
    if(m_pConnection->State)
    {
    m_pConnection->Close();
    //m_pConnection->Release();
    }
    //m_pConnection = NULL;
    }
    }
    else
    {
    //m_pConnection = NULL;
    }
    }
    catch(_com_error e)
    {
    } return bResult;
    }
      

  5.   

    ACCESS与SQL SERVER的删除语句格式不一样,
    一个是delete from table (where ...)
    一个是delete * from table (where ...)
    不知道是否这个原因?