好了,新的问题又来了,
1)我想用vc作一个前端程序,用来访问放在远程服务器上的数据,如何连接数据源.
2)好象用odbc编程时,首先应指定数据源的,这是不是说明该程序只能针对固定的数据源操作,如果想让这个程序访问新的数据源,怎么办?
大家看看吧,总共给足100分,说到办到.

解决方案 »

  1.   

    MS SQL Server OLE DB connection using an IP addressProvider=SQLOLEDB; Data Source=xx.xx.xx.xx,1433; Network Library=DBMSSOCN; Initial Catalog=dbname;User ID=sa;Password=pass;
      

  2.   

    2) you can use dsnless connection string, the above string is a sample.
      

  3.   

    masterz()说的对,这种方法可以不用配置odbc,就可以用ado操作数据库。
      

  4.   

    #import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")int main(int argc, char* argv[])
    {
       CoInitialize(NULL);
       try
       {
          _ConnectionPtr pConn("ADODB.Connection");
          _RecordsetPtr  pRst("ADODB.Recordset");      pConn->Open("Provider=sqloledb;Data Source=Server1;"
             "Initial Catalog=test1;User Id=sa;Password=sa;",
             "", "", adConnectUnspecified);
    // Note 1.
          pRst->Open(
             "userinfo",
             _variant_t((IDispatch *) pConn, true),
             adOpenStatic,
             adLockReadOnly,
             adCmdTable);
          pRst->MoveLast();
    // Note 2.
          printf("Last name is '%s %s'\n",
                (char*) ((_bstr_t) pRst->GetFields()->GetItem("username")->GetValue()),
                (char*) ((_bstr_t) pRst->Fields->Item["otherinfo"]->Value));      pRst->Close();
          pConn->Close();
       }
       catch (_com_error &e)
       {
          printf("Description = '%s'\n", (char*) e.Description());
       }
    ::CoUninitialize();return 0;
    }
      

  5.   

    用SQLConfigDataSource()动态增加自己想要的的数据源。
      

  6.   

    得到用户相连接的数据源名称
    然后CDatabase::Open()时动态的连接数据源
    数据源的注册可以自己通过程序在注册表中写信息得以实现
      

  7.   

    多谢各位了.
    现在我想用ado接口了.客户端程序用来访问放在服务器上的数据库,
    比如说sql serve 2000的northwind.
    我想这样实现:
    在应用程序创建时不指定数据源,运行后,用对话框选择服务器,选择数据库,
    然后进行连接,连接参数要求:用服务器的机器名或服务器的ip地址及端口号
    .我该怎么做?
      

  8.   

    终于明白了:
    ado有连接方式:dsn和dsnless.
    前者要求指定数据源名.后者不用,可以向masterz()说的那样做.
    msdn里有没有这些呢?
    我希望得到关于dsnless连接的更详细信息.哪位有呢?