解决方案 »
- MFC(visual studio2008下的)RichEdit2.0出错!
- Dib图像不显示?? 在线等...
- 我用屏幕录像软件的录像,播放时没有图像但有声音?
- 一个关于CEdit下接收回车键的问题,请各位进来看看!!!
- MFC中调用含WCHAR字符串出错的问题.mbstowcs 和MultiByteWideChar转换时都是只转了第一个字符的问题.
- 求一个客户端的写法
- 关于设备上下文的问题?在线请教高手!!
- (MFC)在获取粘贴板内容上,我是这么做的,有个想法,但不知道应该怎么做?
- CommandPtr 返回记录集
- 怎样在客户区实现一罗扑克牌的显示啊?(内空)
- 广州干VC快2两年了,工资5000怎么样,要换么
- bmp二值化的问题
试试改为一个线程一个Connection
UINT Thread1(LPVOID lpParam)
{
CString str;
clock_t t_Start , t_End;
//初始化COM库
AfxOleInit();
//连接数据库
//建立数据库的连接需要使用Connection Object。步骤如下:
//定义一个_ConnectionPtr类型的指针,代码如下:
//_ConnectionPtr m_pConnection;
//调用CreateInstance方法实例化:
//m_pConnection.CreateInstance(__uuidof(Connection));
CString strSQL;
HRESULT hr;
_ConnectionPtr m_pConnection;
try
{
hr=m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->CursorLocation=adUseClient;
strSQL="Provider=SQLOLEDB;Server=1104A01\\MSSQLSERVER1104;Database=DCS;UID=sa;PWD=726";
if(SUCCEEDED(hr))
{
hr=m_pConnection->Open(_bstr_t(strSQL),"","",adModeUnknown);
}
} catch(_com_error e) //捕捉异常
{
CString errormessage;
errormessage.Format(_T("连接数据库1失败!\r\n错误信息:%s",e.ErrorMessage()));
AfxMessageBox(errormessage);//显示错误信息 return FALSE;
}
_CommandPtr m_pCommand;
try
{ m_pCommand.CreateInstance(__uuidof(Command));
m_pCommand->ActiveConnection = m_pConnection;
m_pCommand->CommandText="Insert_date_data";// 制定调用哪个存储过程
m_pCommand->CommandType=adCmdStoredProc; // 制定Sql命令类型是存储过程
m_pCommand->Parameters->Refresh();m_pCommand->Parameters->GetItem((long)1)->Value ="2013-03-13 21:34:50";//按存储过程的参数顺序给参数赋值
m_pCommand->Parameters->GetItem((long)2)->Value =100;
m_pCommand->Parameters->GetItem((long)3)->Value ="1234567890123456789012345678901234567890123456789012345678901234567890";
} catch(_com_error e) //捕捉异常
{
CString errormessage;
errormessage.Format(_T("连接数据库1失败!\r\n错误信息:%s",e.ErrorMessage()));
AfxMessageBox(errormessage);//显示错误信息 return FALSE;
}
t_Start = clock();
m_pConnection->BeginTrans();
while(num--)
{
m_pCommand->Execute(0,0,adCmdStoredProc);
}
m_pConnection->CommitTrans();
t_End = clock();
str.Format("线程1所用时间为:%d",(t_End - t_Start));
::SetDlgItemText(AfxGetMainWnd()->m_hWnd,IDC_EDIT1,str);
Sleep(2000);
return 0;在线程2中我定义了
_ConnectionPtr m_pConnection2
_CommandPtr m_pCommand2
我用两个编辑框显示每个线程运行的时间,
但是每次只有一个线程能够运行结束,并显示运行时间,另一个线程一进运行数据一直没有写进数据库,这是为什么?有时候线程1正常,有时候线程2正常,求助啊...