现在手里有个项目,是vc6.0开发的一个winform窗体软件,需要实现一个功能:
单击一个按钮,能够实现通过网址或者IP地址连接到一个远程服务器上,服务器上有数据库(oracle或者sql server),在连接到服务器后能够读取出它的数据库上的一些表里的内容,然后再把这些数据显示在本winform窗体上。
要求:连接远程服务器并读取出数据库的操作都在后台进行,不要弹出浏览器,简单说就是只要单击下窗体上的按钮就可以把远程服务器上数据库里的某个表中的数据提取出来并显示。
大家来帮帮我吧,如果能够实现的话将有重谢(现金答谢)!
也可以联系我QQ:260885424或MSN:[email protected]

解决方案 »

  1.   

    补充:数据库为sqlserver2000,开发工具为vc6.0
    怎么没人回答啊?这个问题很难吗?
      

  2.   

    只要你的机器能够访问到这个远程机器,也就是远程机器的IP地址可以寻址到,那就可以,不过这种方法一般不推崇,因为这样你的数据库服务器就暴露在分网上了,本身是不安全的。访问其实很简单就通过ADO就可以很容易地访问。
      

  3.   

    在我的电脑上可以连接,为什么别人的电脑连不上我电脑里的数据库呢,我的数据库服务器已经打开
    代码如下:请高手帮忙分析下
    void CADOdatabaseDlg::OnInitADOConn(CString strsjk)
    {
    ::CoInitialize(NULL);
    CString strname;
            //192.168.0.116是我的电脑即服务器的IP地址
             //Information为要连接的表
    strname.Format("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security  Info=False;InitialCatalog=Information;Data Source=192.168.0.116");
    try
    {
    m_pConnection.CreateInstance("ADODB.Connection");
    _bstr_t strConnect=strname;
    m_pConnection->Open(strConnect,"","",adModeUnknown);
    }
    catch(_com_error e)
    {
    AfxMessageBox(e.Description());
    }
    }
    这段代码在我电脑上是成功的,为什么别人电脑上不成功呢?
      

  4.   

    上面的注释有个错误,//Information为要连接的数据库名称,不是表的名称
      

  5.   

    看看你的连接字符串吧,试试下面的。
    //For Standard   Security:   
     strConnection   =   _T("Driver={SQL   Server};Server=MyServerName;Trusted_Connection=no;"   
      "Database=MyDatabaseName;Uid=MyUserName;Pwd=MyPassword;");   
        
    //For Trusted Connection security: (Microsoft   Windows   NT   integrated   security)   
    strConnection   =   _T("Driver={SQL Server};Server=MyServerName;Database=myDatabaseName;Uid=;Pwd=;");   
        
    //Also you can use the parameter Trusted_Connection that indicates that you are using the   Microsoft   Windows   NT   Authentication   Mode   to   authorize   user   access   to   the   SQL   Server   database.   For   example:   strConnection   =   _T("Driver={SQL   Server};Server=MyServerName;Database=MyDatabaseName;"   
      "Trusted_Connection=yes;");   
        
      //If   the   Sql   Server   is   running   in   the   same   computer   you   can   replace   the   name   of   the   server   by   the   word   (local)   like   in   the   following   sample:   strConnection   =   _T("Driver={SQL   Server};Server=(local);"   
      "Database=MyDatabaseName;Uid=MyUserName;Pwd=MyPassword;");   
      

  6.   

    发现我的命令行下用telnet 192.168.0.116 1433的时候竟然连不上服务器,这该怎么解决啊?
      

  7.   

    //=======================================================//
    //以下为连接SQL SERVER2005数据库,datasource的地方输入IP
    //不过好像2005和2000的连接语句有点不同,你上网查查,2000的多的很
    //=======================================================//
    1.在工程的Cxx.cpp(在A工程中的CAApp类中)的InitInstance()函数中
      /*********初始化COM库***************/
      在MFC中可以用AfxOleInit();
      非MFC环境中用:     
      CoInitialize(NULL);   
      CoUnInitialize();   
    2.在StdAfx.h中
     #import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
    3.为程序添加数据库连接函数OnInitADOConn(),函数名可以任取
    void CDataConDlg::OnInitADOConn()
    {
    /***********连接数据库**************/
    try
    {
         m_pConnection.CreateInstance("ADODB.Connection");
                 /*****************Catalog为你的数据库的名称**********************************/
         CString strConnect="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=FXL;Data Source=.;";
         m_pConnection->Open((_bstr_t)strConnect,"","",adModeUnknown);
            }
    catch(_com_error e)
    {
    AfxMessageBox(e.Description());
    }
    /************数据库连接成功********************/}
    4.需要操作数据库时:
     a.添加成员变量
       _ConnectionPtr m_pConnection;
       _RecordsetPtr m_pRecordset;
     b.建立连接,创建记录集
            OnInitADOConn();
    //UpdateData(true);
    _bstr_t sql;
    sql="select * from FXL_YG";//FXL_YG为数据库中的表名
    m_pRecordset.CreateInstance(_uuidof(Recordset));
    m_pRecordset->Open(sql,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
     c.进行你需要的操作(本例是为数据库添加一条新的记录)
    try
    {
    m_pRecordset->AddNew();
    m_pRecordset->PutCollect("编号",(_bstr_t)number);
    m_pRecordset->PutCollect("姓名",(_bstr_t)name);
    m_pRecordset->PutCollect("学历",(_bstr_t)culture);
    m_pRecordset->Update();
    }
    catch(_com_error e)
    {
    AfxMessageBox("编号重复");
    return;
    }
     d.关闭记录集和连接
    m_pRecordset->Close();
    m_pConnection->Close();
                    CoUninitialize();//关闭com
      

  8.   

    参考下面贴子:
    http://topic.csdn.net/u/20081020/21/77cd5b6b-4717-4496-b028-415989e73a71.html
      

  9.   

    结果还是考虑选择用mysql,毕竟开源的东西嘛,
    就这样吧,结贴了