|
Can someone help me with the below ADO API? I am a new programmer and am having problems programming a SQL Server connection. I have found various connection strings and continue to run into problems with the syntax. Thank you in advance.
#include "stdafx.h"
#include <iostream>
#include <string>
#import "C:\Program files\Common Files\System\Ado\msado15.dll" rename("EOF", "ADOEOF")
//---------------------------------------------------------------------------------------------------------------------------------------------
std::string outputashex(unsigned long l)
{
char buffer[1024];
::itoa(l, buffer, 16);
return buffer;
} ;
//---------------------------------------------------------------------------------------------------------------------------------------------
void main()
{
HRESULT hr;
CoInitialize(NULL);
try
{
ADODB::_ConnectionPtr connection;
hr = connection.CreateInstance(__uuidof(ADODB::Connection));
if (FAILED(hr))
{
throw _com_error(hr);
}
//--------------------------------------------------------------------------------------------------------------------------------------------
ADODB::_RecordsetPtr recordset;
hr = recordset.CreateInstance(__uuidof(ADODB::Recordset));
if (FAILED(hr))
{
throw _com_error(hr);
}
//--------------------------------------------------------------------------------------------------------------------------------------------
connection->CursorLocation = ADODB::adUseClient;
//--------------------------------------------------------------------------------------------------------------------------------------------
connection->Open("Provider=sqloledb;Server=.\SQLExpress;AttachDbFilename=c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\WattsALoan.mdf;Database=WattsALoan;Trusted_Connection=Yes;")
//-------------------------------------------------------------------------------------------------------------------------------------------
//recordset->Open("CREATE TABLE mytable (value NVARCHAR(255))",
//connection.GetInterfacePtr(), ADODB::adOpenForwardOnly,
//ADODB::adLockReadOnly, ADODB::adCmdText);
//--------------------------------------------------------------------------------------------------------------------------------------------
//recordset->Open("INSERT INTO mytable VALUES ('Hello')",
//connection.GetInterfacePtr(), ADODB::adOpenForwardOnly,
//ADODB::adLockReadOnly, ADODB::adCmdText);
//--------------------------------------------------------------------------------------------------------------------------------------------
//recordset->Open("INSERT INTO mytable VALUES ('Goodbye')",
//connection.GetInterfacePtr(), ADODB::adOpenForwardOnly,
//ADODB::adLockReadOnly, ADODB::adCmdText);
//--------------------------------------------------------------------------------------------------------------------------------------------
recordset->Open("SELECT * from Customers",
connection.GetInterfacePtr(),
ADODB::adOpenForwardOnly, ADODB::adLockReadOnly,
ADODB::adCmdText);
//--------------------------------------------------------------------------------------------------------------------------------------------
while(!recordset->ADOEOF)
{
_variant_t var;
var = recordset->Fields->GetItem(L"value")->GetValue();
std::cout << static_cast<char *>(_bstr_t(var.bstrVal))
<< std::endl;
recordset->MoveNext();
};
//--------------------------------------------------------------------------------------------------------------------------------------------
//recordset->Close();
//recordset->Open("DROP TABLE mytable", connection.GetInterfacePtr(),
//ADODB::adOpenForwardOnly, ADODB::adLockReadOnly,
//ADODB::adCmdText);
}
catch(_com_error &e)
{
std::cerr << ::outputashex(hr) << ":"
<< static_cast<char *>(e.Description());
}
catch(...)
{
std::cerr << "Unhandled Exception";
};
}
|
|
|
|
|
I have an application in which a second (worker) thread is created using AfxBeginThread(). The execution of this thread can be stalled due to a WaitOnSingleObject(), which MAY never get signalled. In this situation, when the application main thread terminates, I get a memory leak as follows:-
Detected memory leaks!
Dumping objects ->
strcore.cpp(118) : {78} normal block at 0x003011E0, 16 bytes long.
Data: < D:\ > 01 00 00 00 03 00 00 00 03 00 00 00 44 3A 5C 00
strcore.cpp(118) : {77} normal block at 0x00301220, 59 bytes long.
Data: < . Thre> 01 00 00 00 11 00 00 00 2E 00 00 00 54 68 72 65
thrdcore.cpp(166) : {71} client block at 0x003014C0, subtype 0, 112 bytes long.
a CWinThread object at 003014C0, 112 bytes long
If the WaitOnSingleObject gets signalled, then there is no memory leak.
I have tried various things to get over this problem, but have had no success. How should I properly deal with a waiting thread to avoid the memory leak ? (Apologies if this is a "trivial" question to the more experienced "threaders" !!)
Doug
|
|
|
|
|
Add a "Terminate" event and then do a WaitOnMultipleObjects() with the terminate event handle first in the array. When you need to terminate, set the terminate event and sleep at least 0 (to give the other thread a chance to run.) Have the thread then exit normally and it will do cleanup.
A more sophisticated solution is to wait on the thread handle after you set the terminate event, though AfxBeginThread() makes this a bit tricky.
|
|
|
|
|
Hi Joe, I had actually implemented your first solution already, except for the Sleep(0) - I NOW realise that there was a thread "race", which therefore still allowed failure. I also found that it works just as well with the terminate event handle in the second position in the array - have I missed something ? Many thanks for your help by the way !!
Doug
|
|
|
|
|
I say put the terminate first because the wait processes objects in order. If the terminate event is last in the list and the previous events keep going signaled, you may never pick up that the terminate event is signaled (unless you check it after the WaitForMultipleObjects.)
|
|
|
|
|
Of course !! Thanks again for your help
Doug
|
|
|
|
|
Have a look here[^] for a more descriptive explanation of what Joe is talking about.
You'll also find a lot of things that are Really Good To Know regarding multithreading in the article.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Is it possible to make vertical scrollbar to smooth scroll contents of the list control?
I want to have the same behavior as horizontal scrollbar has.
|
|
|
|
|
Hello, I downloaded B+ tree template from ScalingWeb:
http://www.scalingweb.com/downloads/B+Tree-1.0.zip
but the problem is that I can't make it work, because it uses Qt. I never faced with Qt and don't know what to do. After downloading Qt SDK and reading help, I still don't understand how to make this template work
Can someone explain how to use Qt in this situation?
I sit on Windows XP.
|
|
|
|
|
Hello,
There is a Forum for QT[^] and you may possibly get better help there (with regards to QT).
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi!
I can not register an ActiveX control on my Vista.
When I do regsvr32 c:\windows\system32\MyActivX.ocx (i write this command in command prompt),
I got an error: MyActivX.ocx was loaded but the call to DLLRegisterServer failed with error code 0x80040200.!!!
I login to the Vista with Administrator, and Right click on the icon for Command Prompt on the start menu and select Run as Administrator.
but I got this error message, yet!!!
Can anyone give an idea what i'm doing wrong???
Zo.Naderi-Iran
|
|
|
|
|
Try opening the command prompt with elevated privileges by right clicking on the shortcut and selecting "Run as Administrator".
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I did this work, but I got this error message, yet!!!
I login to the Vista with Administrator, and Right click on the icon for Command Prompt on the start menu and select Run as Administrator.
is there other idea?
Zo.Naderi-Iran
|
|
|
|
|
Its probably because of some dependency DLL issue.
If you're having this problem on a fresh machine make sure you create an MSI with all the required dependencies like MFC dependencies, CRT dependencies etc.
If this problem is on a development machine, try recompiling the ActiveX on Vista.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
my problem is on a development machine,
ok, i will recompile the ActiveX on Vista, and i will test it.
thank you
Zo.Naderi-Iran
|
|
|
|
|
Hi
I am writing mapi application, where how can print mail create time.
PR_CREATION_TIME, how i will print this property, this returns systime of value.
thanx in advance
sampath-padamatinti
|
|
|
|
|
Hi,
i have a resource file in which i have changed the font property of the dialog to "Arial" regular
20....
then the font inside the dialog got increased...along with the text of the controls inside dialog..
and now i tried changing from the code in initDialog function like...
CFont newfont;
LOGFONT lf;
SecureZeroMemory(&lf, sizeof(lf));
lf.lfHeight = 20;
lf.lfWeight = FW_MEDIUM;
lstrcpy(lf.lfFaceName, _T("Arial"));
newfont.CreateFontIndirect(&lf);
GetDlgItem(IDC_CHECK1)->SetFont(&newfont);
GetDlgItem(IDC_STATIC)->SetFont(&newfont);
newfont.Detach();
and now when i build and see the output the look of the dialog with new font is not same and even the font looks smaller than the font of the dialog which i have tried to change manually the font property of the Dialog....
Please suggest me how can i make changes to my code so that both look similar....
|
|
|
|
|
assume the table has 6 records, user ID are 0, 1, 3, 5, 6, 7 respectively.
now I need to insert a new user with min valid user ID.
in sample above, the min valid ID is 2.
what is good SQL statement to inser the new user?
if it is imposible to insert directly, what is good SQL to find the min ID first?
the database is very large actually, so enum all records may be no good.
|
|
|
|
|
Hello all,
I have 2 property pages:
Property Page1 thats a size of 252 x 354.
Property Page2 thats a size of 252 x 100.
When I run the application I get a Property Sheet that's size 252x354. The size remains the same even if I select the second page.
Is it possible to resize the Property Sheet to the size of the page that's currently selected?
Thanks
|
|
|
|
|
Assuming you're using MFC, override the OnSetActive function of the CPropertyPage derived class.
This is called every time a property page is selected.
From this function you could resize the parent sheet using GetParent()->SetWindowPos(... .
But you may not be able to get the required page size from OnSetActive because the page is resized to the largest page size. You may have to do that from other functions like OnInitDialog .
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
|
Creating a dynamic 2-dimensional array (matrix) using a pointer-to-pointer works for small matrices. If I try to allocate huge matrices (with new), not necessarily larger than the available memory, no bad_alloc exception is thrown and linux becomes very slow!
With one dimensional array (vector) it works perfectly: as soon as you exceed ram+swap a bad_alloc exception is thrown.
Can anybody confirm?
Is this due to the fact that if the matrix is huge each element of the array of pointers has to point to numerous elements and it is not guaranteed that consecutive memory is available??
|
|
|
|
|
Hi,
I am writing a mapi sample, where mapi intializing is done perfectly, also logon is also happens perfectly, but the third function that is
"HrOpenExchangePrivateStore(lpSession,&lpStore)", function always returning false value, please tell me what should give the value here for lpstore.
I am usin the following link.
http://support.microsoft.com/kb/200181/EN-US/
thanx in advance
sampath-padamatinti
|
|
|
|
|
When I need to override a function like CDocument::OnOpenDocument, in VC6 I'd use the "Add Virtual Function" from class view context menu, but it's missing in VS2008. Is the feature moved to some place else or is it missing?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
It is available in VS 2008, only thing is that it is different from VC6.
Take Class View, right click on your document class or which ever class.
Select Properties.
One of the icons on the top is Overrides.
That is what you're looking for.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|