VS2010 + SQL 2005 1 安装SQL 2005 2 控制面板-管理工具-本地服务。MSSQLSERVER 运行 3 SQL Server Configuration Manager 网络配置中的Named Pipes,TCP/IP 启动。 4(如果要使用SA 登录模式,本教程无需操作)安装 SQL server Management Studio Express,中修改服务器连接方式为“windows ,数据库混合登录模式” 01、打开数据库——用 Window s 身份登录数据库 02、登录名——双击 sa(打开属性) 0 3 、常规——设置密码——确定 0 4 、状态——登录:启用——确定 0 5 、 右击服务器名——属性 06、安全性——选中 SQL Server 和 Window s 身份验证模式——确定 07、 右击服务器名——重新启动——关闭数据库连接,退出程序——用 sa 登录到数据库 VS2010 代码: stdafx.h中添加 #import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","EndOfFile") rename("BOF","BeginOfFile") IDC_Button1 { //windows 验证模式 ::CoInitialize(NULL); _ConnectionPtr xhConnPtr(__uuidof(Connection)); _RecordsetPtr xhRcdPtr(__uuidof(Recordset)); try { xhConnPtr->ConnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=cangqiong;Data Source=FREE-X"; xhConnPtr->Open("","","",adConnectUnspecified); } catch (_com_error e) { MessageBox(e.Description(),"notice",MB_YESNO); } //--------------------------------------------------- try { xhRcdPtr=xhConnPtr->Execute("select * from test",NULL,adCmdText); } catch (_com_error e) { AfxMessageBox(e.Description()); } //---------------------------------------------------- try { CString s; GetDlgItemText(IDC_EDIT1,s); SetDlgItemText(IDC_EDIT1,s+(LPCSTR)_bstr_t(xhRcdPtr->GetCollect("name"))); xhRcdPtr->MoveNext(); GetDlgItemText(IDC_EDIT1,s); SetDlgItemText(IDC_EDIT1,s+(LPCSTR)_bstr_t(xhRcdPtr->GetCollect("name"))); } catch(_com_error e) { AfxMessageBox(e.Description()); } xhRcdPtr->Close(); }