注册 登录
编程论坛 VC++/MFC

用ADO连接SQL数据库的问题! 急!!!!!!!!!!

xjlsgcjdtc 发布于 2007-12-02 15:40, 2729 次点击
我想用ADO连接SQL Server数据库

但是编译的时候老报错   智能指针未定义

错误如下:

d:\program files\microsoft visual studio\myprojects\图书管理系统 1\1.h(25) : error C2146: syntax error : missing ';' before identifier 'm_pConnection'
d:\program files\microsoft visual studio\myprojects\图书管理系统 1\1.h(25) : error C2501: '_ConnectionPtr' : missing storage-class or type specifiers
d:\program files\microsoft visual studio\myprojects\图书管理系统 1\1.h(25) : error C2501: 'm_pConnection' : missing storage-class or type specifiers
d:\program files\microsoft visual studio\myprojects\图书管理系统 1\1dlg.h(19) : error C2146: syntax error : missing ';' before identifier 'm_pRecordset'
d:\program files\microsoft visual studio\myprojects\图书管理系统 1\1dlg.h(19) : error C2501: '_RecordsetPtr' : missing storage-class or type specifiers
d:\program files\microsoft visual studio\myprojects\图书管理系统 1\1dlg.h(19) : error C2501: 'm_pRecordset' : missing storage-class or type specifiers
D:\Program Files\Microsoft Visual Studio\MyProjects\图书管理系统 1\1.cpp(67) : error C2065: 'm_pConnection' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\图书管理系统 1\1.cpp(67) : error C2228: left of '.CreateInstance' must have class/struct/union type
D:\Program Files\Microsoft Visual Studio\MyProjects\图书管理系统 1\1.cpp(70) : error C2227: left of '->Open' must point to class/struct/union

但是我在 stdafx.h 中已经加入了
#import "C:\program files\common files\system\ado\msado15.dll"  no_namespace rename("EOF","adoEOF") rename("BOF","adoBOF")

在应用程序类中加入了 (我在最初注册SQL 服务器组的时候 用的是"windows身份验证",而不是"SQL Server验证",所以没有用户名和密码)

 if(! AfxOleInit())
    {
        AfxMessageBox("初始化失败!");
            return FALSE;
    }
 AfxEnableControlContainer();
 //初始化com对象
 CoInitialize(NULL);
 try
 {
  //初始化数据连接对象
  m_pConnection.CreateInstance("ADODB.Connection");
  m_pConnection->Open("driver={SQL Server};Server=2AD32E4C8D614AD;DATABASE=libruary;UID='';PWD=''","","",adModeUnknown);
 }
 catch (_com_error* e)
 {
  AfxMessageBox(e.Description());
 }

如果我在主对话框类中加入
#import "C:\program files\common files\system\ado\msado15.dll"  no_namespace rename("EOF","adoEOF") rename("BOF","adoBOF")
编译器就不会报错,但是连不上数据库!
紧急求救!
1 回复
#2
xe5698860482010-12-10 22:17
主对话框  包含ADO类了么?
1