生成没有问题,运行时出错
错误代码如下:
SQLTest.exe”: 已加载“E:\SY\SQLTest\Debug\SQLTest.exe”,已加载符号。
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\ntdll.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\kernel32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\KernelBase.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\ole32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\msvcrt.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\gdi32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\user32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\advapi32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\sechost.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\rpcrt4.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\sspicli.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\cryptbase.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\lpk.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\usp10.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\oleaut32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\msvcp100d.dll”,已加载符号。
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\msvcr100d.dll”,已加载符号。
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\apphelp.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\AppPatch\AcLayers.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\shell32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\shlwapi.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\userenv.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\profapi.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\winspool.drv”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\mpr.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\imm32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\msctf.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\uxtheme.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“D:\360\360Safe\safemon\safemon.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\psapi.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\wininet.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\urlmon.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\crypt32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\msasn1.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\iertutil.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\version.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\ws2_32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\nsi.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\netapi32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\netutils.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\srvcli.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\wkscli.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\clbcatq.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Program Files (x86)\Common Files\System\ado\msado15.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\msdart.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\cryptsp.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\rsaenh.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\RpcRtRemote.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Program Files (x86)\Common Files\System\Ole DB\oledb32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\bcrypt.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_41e6975e2bd6f2b2\comctl32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Program Files (x86)\Common Files\System\Ole DB\oledb32r.dll”,未使用调试信息生成二进制文件。
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\comsvcs.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\atl.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\bcryptprimitives.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Program Files (x86)\Common Files\System\Ole DB\sqloledb.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Program Files (x86)\Common Files\System\Ole DB\msdatl3.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\dbnetlib.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\security.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\secur32.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\credssp.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\msv1_0.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\cryptdll.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\ntdsapi.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“D:\SogouExplorer\sogouipfilter.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\imagehlp.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\mswsock.dll”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\WSHTCPIP.DLL”,Cannot find or open the PDB file
“SQLTest.exe”: 已加载“C:\Windows\SysWOW64\dbnmpntw.dll”,Cannot find or open the PDB file
线程 'Win32 线程' (0x17c8) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x1430) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x744) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x658) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x17bc) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x121c) 已退出,返回值为 -1073741510 (0xc000013a)。
程序“[5968] SQLTest.exe: 本机”已退出,返回值为 -1073741510 (0xc000013a)。
代码如下:// SQLTest.cpp : 定义控制台应用程序的入口点。#include "stdafx.h"
#include "iostream"
#include "icrsint.h"
#import "c:\program files\common files\system\ado\msado15.dll"  no_namespace rename("EOF", "adoEOF")
using namespace std;int _tmain(int argc, _TCHAR* argv[])
{
//初始化COM(在Dll中调用COM时(比如ADO等)必须先用CoInitialize(NULL)初始化COM)
::CoInitialize(NULL);
//创建连接对象
_ConnectionPtr m_pConnection;
//实例化连接对象
m_pConnection.CreateInstance("ADODB.Connection");
//建立(打开)连接
//m_pConnection->Open("Server=IP,端口号;uid=数据库登录名;pwd=登录密码;DATABASE=数据库名称;Provider=SQLOLEDB;","","",-1);
m_pConnection->Open("Server=192.168.27.66,3257;uid=sa;pwd=JZSX_123;DATABASE=ControlAlarmVideoService;Provider=SQLOLEDB;","","",-1);
//创建结果集
_RecordsetPtr m_pRecordset;
//实例化结果集
m_pRecordset.CreateInstance("ADODB.Recordset");
//执行SQL语句
m_pRecordset->Open("SELECT id,DepartmentName,Description FROM ControlAlarmVideoService.Control.DepartMentInfo",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);  _variant_t var;
char *id,*DepartmentName,*Description; try
{
//如果结果集不为空
if(!m_pRecordset->BOF)
//结果集指向第一行
m_pRecordset->MoveFirst();
//如果结果集为空
else {
printf("表内数据为空");
return 1;
}
//结果集中还有数据行
while(!m_pRecordset->adoEOF)
{
//将结果集中第一行对应userId的列值赋值给var
var = m_pRecordset->GetCollect("id");
//如果值不为空
if(var.vt != VT_NULL)
//将var的值类型转换后赋值给ID
id= _com_util::ConvertBSTRToString((_bstr_t)var); var=m_pRecordset->GetCollect("DepartmentName");
if(var.vt !=VT_NULL)
DepartmentName=_com_util::ConvertBSTRToString((_bstr_t)var); var = m_pRecordset->GetCollect("Description");
if(var.vt != VT_NULL)
Description=_com_util::ConvertBSTRToString((_bstr_t)var); //cout<<ID<<" is "<<name<<endl;
//打印出结果
printf("id:%s\t DepartmentName:%s\t Description:%s\n ",id,DepartmentName,Description);
m_pRecordset->MoveNext();

}
//捕获错误并打印
catch(_com_error *e)
{
cout<<e->ErrorMessage()<<endl;
}
//关闭结果集
m_pRecordset->Close();
//设置结果集为空
m_pRecordset = NULL;   
//如果连接状态开启,则关闭连接
if(m_pConnection->State)
m_pConnection->Close();
//设置连接为空
m_pConnection= NULL;
getchar();//用户输入字符,让dos窗口保持显示
return 0;
}