请问在VC程序中如何与一个SQL SERVER数据库连接呢? 请问在VC程序中如何与一个SQL SERVER数据库连接呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ADO /*初始化COM对象,创建智能指针实例,连接数据库*/ if (!AfxOleInit()) { AfxMessageBox("ole 初始化错误"); return FALSE; } splashDlg->SetInfoText(_T("联接远程数据库服务器...")); CString strOpen = "Provider=SQLOLEDB;Network Library=DBMSSOCN;Data Source=xxx.xxx.xxx.xxx;Initial Catalog=urDB;User ID=sa; Password=pass"; try { m_pConnection.CreateInstance(__uuidof(Connection)); m_pConnection->Open((const char *)strOpen,"","",-1); m_pConnection->CursorLocation = adUseClient; } catch(...) { AfxMessageBox("联接服务器失败,程序将关闭!!!"); return FALSE; } 请教OPCV中的分水岭算法 有不能被派生的类吗? mfc真的公开了所有的源代码么? Menu的问题 谁有类似windows 画图软件的源码(工具的编写方法)? 为什么我的组件注册失败?return code 0x8007007e 窗口怎么会起动两次。 service中如何在运行时改变自己的身份? 有关CHtmlView的问题 市面上有这种路由买吗? 如何检查内存泄漏? 求助:如何使基于CEditView的单文档视图的程序在启动时自动使框架调整到自已定制的大小?
/*初始化COM对象,创建智能指针实例,连接数据库*/
if (!AfxOleInit())
{
AfxMessageBox("ole 初始化错误");
return FALSE;
}
splashDlg->SetInfoText(_T("联接远程数据库服务器...")); CString strOpen = "Provider=SQLOLEDB;Network Library=DBMSSOCN;Data Source=xxx.xxx.xxx.xxx;Initial Catalog=urDB;User ID=sa; Password=pass"; try
{
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open((const char *)strOpen,"","",-1);
m_pConnection->CursorLocation = adUseClient;
}
catch(...)
{
AfxMessageBox("联接服务器失败,程序将关闭!!!");
return FALSE;
}