请问用ADO连接远程数据库的连接字符串是什么

解决方案 »

  1.   

    这个我来回答,正好前几天写了一篇关于ADO的文章,摘录几段看看吧:
    -----------------------------------------------------------------
    2.数据库连接字符串的写法:
    以下就是进行数据库的连接,由于ADO支持的数据库种类繁多,因此连接也相当复杂。从连接类型可以分为两种:1.采用连接字符串;2.使用UDL文件。对于每种方法又有不同的写法。
    ①.连接字符串
    ===>Access Connect String
    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=dbtest.mdb
    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=dbTest.mdb;Jet OLEDB:Database Password=********;");
    ===>SQLServer Connect String
    Driver=SQL Server;Database=fwbmk;Server=127.0.0.1;UID=sa;PWD=xx; (自带)
    使用标准安全级别:
    strConnect = _T("Provider=sqloledb;Data Source=MyServerName;Initial Catalog=MyDatabaseName;User Id=MyUsername;Password=MyPassword;");
    使用信任连接:
    strConnect = _T("Provider=sqloledb;Data Source=MyServerName;Initial Catalog=MyDatabaseName;Integrated Security=SSPI;");
    指定SQLServer实例:
    strConnect = _T("Provider=sqloledb;Data Source=MyServerName\MyInstanceName;Initial Catalog=MyDatabaseName;User Id=MyUsername;Password=MyPassword;");
    本地数据库:
    strConnect = _T("Provider=sqloledb;Data Source=(local);Initial Catalog=myDatabaseName;User ID=myUsername;Password=myPassword;");
    网络数据库:
    strConnect = _T("Provider=sqloledb;Network Library=DBMSSOCN;Data Source=130.120.110.001,1433;Initial Catalog=MyDatabaseName;User
    3
    计算机软件技术《数据库部分》——ADO开发应用程序ID=MyUsername;Password=MyPassword;");
    ===>Oracle Connect String
    微软提供的Oracle标准连接是:
    strConnect = _T("Provider=MSDAORA;Data Source=serverName;User ID=userName; Password=userPassword;");
    Oracle公司提供的连接方式:
    使用标准安全级别:
    strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;");
    使用信任连接
    1.strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=/;Password=;"); UID为'/'
    2.strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;");使用OSAuthent=1
    对于连接字符串可以参考以下网页: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdreforacleprovspec.asp?frame=true
    http://download-west.oracle.com/otndoc/oracle9i/901_doc/win.901/a90171/using.htm
    ===>ODBC 配置数据源
    strConnect = _T("DSN=ADOTest");
      

  2.   

    使用SQL Server
    ConnectionString = L"Driver={SQL Server};UID=sa;Password=;Database= ;Server=;"ConnectionString = L"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=;Data Source=";
      

  3.   

    /connect romote computer
    ConnectionPtr m_conn; HRESULT hr;
    hr=m_conn.CreateInstance(__uuidof(Connection));
    if(!SUCCEEDED(hr))
    AfxMessageBox("创建连接失败");
    sql="provider=SQLOLEDB;Data Source=127.0.0.1;Initial Catalog=yourDB;User ID=sa;Password=";
    try
    {
    hr=m_conn->Open(_bstr_t(sql),"","",adModeUnknown);
    if(SUCCEEDED(hr))
    m_bconn=true;
    else
    {
    m_bconn=false;
    return false;
    }
    }
    catch (_com_error &e) // Any errors?
    {

    // Display the error
    CString strError;
    strError.Format("连接时出错: '%d (%x)'",e.Error(),e.Error() );
    strError +="\n";
    strError +=e.Description();
    AfxMessageBox("连接数据库失败\n"+strError);
    return FALSE;
    }
      

  4.   

    connect romote computer
    ConnectionPtr m_conn; HRESULT hr;
    hr=m_conn.CreateInstance(__uuidof(Connection));
    if(!SUCCEEDED(hr))
    AfxMessageBox("创建连接失败");
    sql="provider=SQLOLEDB;Data Source=127.0.0.1;Initial Catalog=yourDB;User ID=sa;Password=";
    try
    {
    hr=m_conn->Open(_bstr_t(sql),"","",adModeUnknown);
    if(SUCCEEDED(hr))
    m_bconn=true;
    else
    {
    m_bconn=false;
    return false;
    }
    }
    catch (_com_error &e) // Any errors?
    {

    // Display the error
    CString strError;
    strError.Format("连接时出错: '%d (%x)'",e.Error(),e.Error() );
    strError +="\n";
    strError +=e.Description();
    AfxMessageBox("连接数据库失败\n"+strError);
    return FALSE;