请问在VC程序中如何与一个SQL SERVER数据库连接呢?

解决方案 »

  1.   

    ADO
    /*初始化COM对象,创建智能指针实例,连接数据库*/
    if (!AfxOleInit())
    {
    AfxMessageBox("ole 初始化错误");
    return FALSE;
    }
    splashDlg->SetInfoText(_T("联接远程数据库服务器...")); CString strOpen = "Provider=SQLOLEDB;Network Library=DBMSSOCN;Data Source=xxx.xxx.xxx.xxx;Initial Catalog=urDB;User ID=sa; Password=pass"; try
    {
    m_pConnection.CreateInstance(__uuidof(Connection));
    m_pConnection->Open((const char *)strOpen,"","",-1);
    m_pConnection->CursorLocation = adUseClient;
    }
    catch(...)
    {
    AfxMessageBox("联接服务器失败,程序将关闭!!!");

    return FALSE;
    }