用MFC连接sql server 2008 r2数据库,死活连不上,求大神!!!
CoInitialize(NULL);//初始化com库;ado是个com组件,所以得先初始化com库pConn.CreateInstance("ADODB.Connec...
CoInitialize(NULL);//初始化com库;ado是个com组件,所以得先初始化com库
pConn.CreateInstance("ADODB.Connection");
// pRst.CreateInstance("ADODB.Recordset");
pConn->ConnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ASP;Data Source=.;Uid=sa;Pwd=yuan;";//链接语句期中test为数据库名称
try
{
pConn->Open("","","",adConnectUnspecified);
// AfxMessageBox("连接数据库成功");
}
catch(_com_error ex)
{
AfxMessageBox(ex.Description());
}
return TRUE; 展开
pConn.CreateInstance("ADODB.Connection");
// pRst.CreateInstance("ADODB.Recordset");
pConn->ConnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=ASP;Data Source=.;Uid=sa;Pwd=yuan;";//链接语句期中test为数据库名称
try
{
pConn->Open("","","",adConnectUnspecified);
// AfxMessageBox("连接数据库成功");
}
catch(_com_error ex)
{
AfxMessageBox(ex.Description());
}
return TRUE; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询