ADO连接本地SQLServer数据库,连接不上。我安装的是windows验证模式,那创建connection对象时那些参数如何填写?

解决方案 »

  1.   

    BOOL CDlgDBConnect::ConnectSQLServer()
    {
    if (m_strService.IsEmpty())
    {
    ::MessageBox(NULL,"·þÎñÃû²»ÄÜΪ¿Õ","Ìáʾ",MB_OK);
    return FALSE;
    }
    if (m_strDatabase.IsEmpty())
    {
    ::MessageBox(NULL,"Êý¾Ý¿â²»ÄÜΪ¿Õ","Ìáʾ",MB_OK);
    return FALSE;
    } theApp.m_pConnection.CreateInstance(__uuidof(Connection)); 
    try                 
    {
    theApp.m_strDatabase=m_strDatabase; CString strConn;
    strConn="Provider=SQLOLEDB.1;Password=";
    strConn+=m_strPassword;
    strConn+=";Persist Security Info=True;User ID=";
    strConn+=m_strUsername;
    strConn+=";Initial Catalog=";
    strConn+=m_strDatabase;
    strConn+=";Data Source=";
    strConn+=m_strService;
    theApp.m_pConnection->Open((_bstr_t)strConn,
       "",
       "",
       adModeUnknown);
    }
    catch(_com_error e)
    {
    ::MessageBox(NULL,e.Description(),"Ìáʾ",MB_OK);
    return FALSE;
    }

    ::MessageBox(NULL,"Êý¾Ý¿âÁ¬½Ó³É¹¦£¡","Ìáʾ",MB_OK);
    return TRUE;}
      

  2.   

    try
    {
    // 创建Connection对象
    m_pConnection.CreateInstance("ADODB.Connection");
    // 设置连接字符串,必须是BSTR型或者_bstr_t类型
    _bstr_t strConnect = "Provider=SQLOLEDB;        Server=ntserver;Database=Assets; uid=sa; pwd=sa;";
    m_pConnection->Open(strConnect,"","",adModeUnknown);
    我是用的别人的一个程序,然后在本机上建的一个数据库,我用的是windows的验证模式,上面的那个参数应该如何修改?
      

  3.   

    Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=database;Data Source=server