开发者

ADO command tsql insert query issues

In my C++ code, when I try to run the ADO command to insert rows into a table, it only inserts a certain number of rows. The same command works well when using System.Data.SqlClient in .NET.

Sql profiler shows the same textdata when using ADO or a sqlclient. Below is my insert commandtext, I'm not sure what else to do to uncover the issue here.

Any help on this is appreciated.

Command text :

declare @i int set @i = 1 while (@i < 255) 
begin 
  insert into table1 (name,type, order, state) values (@i, N'type',0,0) 
     set @i = @i +1 
end

The above command ends at 153 rows. Is this dependent on table size ? If I send the command execute twice, consecutively one ranging from @i 0 to 150 and another from 150 to 255, all rows are inserted fine. Am I'm hitting a limit on ADO command execute ?

This is my connection string and the code I'm using to build the connection :

CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
ADODB::_ConnectionPtr m_Conn = NULL;  
TCHAR connString[255];
  _stprintf(connString, 
      _T("DRIVER=SQL Server;SERVER=np:(local)\\MyInstance;DATABASE=test;"));

   HRESULT hr;
   hr = m_Conn.CreateInstance(__uuidof(ADODB::Connection));
   if (hr != S_OK) {
     wprintf(_T("CreateInstance(__uuid开发者_JAVA百科of(ADODB::Connection)) failed. Error: %d"), hr);
     return 0;
   }

   m_Conn->ConnectionTimeout = 1800;
   m_Conn->CommandTimeout = 1800;

   hr = m_Conn->Open((LPCTSTR)connString, _T(""), _T(""), 
       ADODB::adConnectUnspecified);
   if (hr != S_OK) {
     wprintf(_T("Open(%ws, '', '', ADODB::adConnectUnspecified) failed."),
         connString);
     return 0;
   }

Thanks for your help.


I got it work. Adding 'SET NOCOUNT ON' allowed the insert to continue. Not sure what the limit is in ADO.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜