调用SQLDriverConnect总是出错。没法连上。请问谁能简单介绍一下他的语法??

解决方案 »

  1.   

    相同程序在别的电脑上能够运行的。为什么在本地电脑不能连接呢==>>可能你的dns没配置好吧
      

  2.   

    RETCODE retcode;
        unsigned char  szDSN[SQL_MAX_DSN_LENGTH+1] = "DBName",
                       szUID[MAXNAME]              = "user",
                       szAuthStr[MAXNAME]          = "pwd";    retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
    retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
                                (SQLPOINTER)SQL_OV_ODBC3,
                                SQL_IS_INTEGER);
    retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
        retcode = SQLConnect(hdbc1,
                            szDSN, SQL_NTS,   
            szUID, SQL_NTS,
                            szAuthStr, SQL_NTS);    if ((retcode != SQL_SUCCESS) && 
            (retcode != SQL_SUCCESS_WITH_INFO)) 
    AfxMessageBox("连接数据库错误."); 
               else 
      AfxMessageBox("Connection succeed.\n");  retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc1, &hstmt1);  CString sqlStr;
     CString str;
     sqlStr="insert into TEST(ID,NAME) VALUES(1,'45')";
     
        unsigned char *sqlText=(unsigned char *)SqlChr;    retcode = SQLPrepare(hstmt1,
                             sqlText, 
           SQL_NTS);
    retcode = SQLExecute(hstmt1);
    if ((retcode != SQL_SUCCESS) && 
            (retcode != SQL_SUCCESS_WITH_INFO) ) 
    AfxMessageBox("失败.");
        else 
         AfxMessageBox("成功."); if (pDataBuffer) delete [] pDataBuffer;
    SQLFreeHandle(SQL_HANDLE_STMT, hstmt1);
        SQLDisconnect(hdbc1);
        SQLFreeHandle(SQL_HANDLE_DBC, hdbc1);
        SQLFreeHandle(SQL_HANDLE_ENV, henv);
      

  3.   

    请问dns是什么?怎么配置
    我用的是driver关键字,还需要dns嘛???
      

  4.   

    HRESULT hr;
    CString strConnection = "Provider=MSDAORA;Data Source=a;User ID=b; Password=c"; try
    {
    hr =m_pConnection.CreateInstance("ADODB.Connection");
    if(SUCCEEDED(hr))
    {
    hr=m_pConnection->Open((_bstr_t)strConnection,"","",-1);
    }
    }
    catch(_com_error e)
    {
    // CCommon common;
    // AfxMessageBox(common.DisplayAdoError(m_pConnTemp));
    AfxMessageBox(e.ErrorMessage());
    }
    ado连接数据库,不过要注意如果你是客户端,数据源 a 要同客户端配的一致!