小弟忘了,vc用ado连接sqlserver的方法,请高手指点

解决方案 »

  1.   

    新建文本文件
    更名为*.udl文件(如Connection.udl)
    双击打开
    建立连接
    确定
    用文本文件打开,里面有你要的ConnectionString
      

  2.   

    CString strConnectionstring;
    strConnectionstring="Provider=SQLOLEDB.1;Data Source=(local);
      Initial Catalog= YourSQLdatabase;user ID=sa;PWD=xxx";这里假定是本地服务器:(local),数据库是:YourSQLdatabase 用户是:sa  密码是:xxx
    根据你的情况修改即可.
      

  3.   

    在StdAfx.h文件中加#import "e:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")BOOL CADOBlobApp::InitInstance()
    {
    AfxEnableControlContainer();
    AfxOleInit();
    m_pConnection.CreateInstance("ADODB.Connection");
    /******************连接数据库********************/
    try
    {
    m_pConnection->ConnectionTimeout = 8;
    //连接SQL SERVER
    //m_pConnection->Open("Driver=SQL Server;Database=test;Server=127.0.0.1;UID=sa;PWD=;","","",adModeUnknown);
    //连接ACCESS2000
    m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=userinfo.mdb","","",adModeUnknown);
    }
    catch(_com_error e)///捕捉异常
    {
    AfxMessageBox("数据库连接失败!");
    return FALSE;
    }
      

  4.   

    更正,在StdAfx.h文件中加#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")你的系统盘