首页 > 代码库 > ADO----nDSN
ADO----nDSN
//////////////链接数据库 非DSN模式/////////////////////////////
//CString strOpen="DSN=DBAddressBook;UID=sa;PWD=123456";
//m_pConnection.CreateInstance(__uuidof(Connection));
//m_pConnection->Open("Provider=SQLOLEDB;SERVER=R-PC;DATABASE=;UID=;PWD=;","","",-1);
//try
//{
// m_pConnection.CreateInstance("ADODB.Connection"); //创建连接对象实例
//_bstr_t strConnect="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Restaurant;Data Source=(教师机\\SQLEXPRESS)";
//_bstr_t strConnect="driver={SQL Server};Server=R-PC;DATABASE=DBAdressBook;UID=sa;PWD=123456";
//m_pConnection->Open(strConnect,"","",adModeUnknown); //打开数据库
//}
//catch (_com_error e) //捕捉错误
//{
//AfxMessageBox(e.Description()); //弹出错误
//}
try
{
m_pConnection.CreateInstance("ADODB.Connection");
_bstr_t strConnect="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DBAdressBook;Data Source=xxxx";
//_bstr_t strConnect="driver={SQL Server};Server=xxxx;DATABASE=DBAdressBook;UID=sa;PWD=xxxxx";
m_pConnection->Open(strConnect,"","",adModeUnknown);
AfxMessageBox("连接成功");
}
catch(_com_error e)
{
AfxMessageBox("连接失败");
}
//////////////////////////////////////////