|
hi, writing a win32 console app that doesnt support MFC (besides CDBException is for ODBC ..)
i opened a recordset and since the open method doesnt return a HRESULT, i need to use try-catch mechanism.
but how?
try
{
pRs->Open(....);
}
catch( what?)
{
}
Reference:
recordset.Open Source, ActiveConnection, CursorType, LockType, Options
(Note: No return value)
thanks gurus!
norm
|
|
|
|
|
if you catch (...), you'll catch all exceptions. There is a com_exception, or similar, but I forget exactly what it's called.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
just found out...
try
{
pRs->Open(vNull, vNull, adOpenForwardOnly, adLockReadOnly, adCmdUnknown);
}
catch(_com_error &e)
{
//Additional error handling here.
cout << "ERROR: Failed to open recordset." << endl;
cout << "ERROR msg: " << e.ErrorMessage() << endl;
}
But the error msg is soooo vague:
Unknown error 0x800A0E79
I'm banging my head against my cactus but apparently it doesnt help
norm
|
|
|
|
|
In the tools menu of VC is an error number checker. Put this number into it and it will pop up a dialog that says 'error message not found'. Or, 1 in 1,000 times, it knows what this HRESULT means, and then it tells you
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
tried, it says cant find the message ("Message not found") with "0x800A0e79"..
the tool is called "Error Lookup"
catch(_com_error &e)
{
//Additional error handling here.
cout << "ERROR: Failed to open recordset." << endl;
cout << "ERROR: e.ErrorMessage(): " << e.ErrorMessage() << endl;
hr = e.Error();
cout << "ERROR: HRESULT_CODE( e.Error() ): " << HRESULT_CODE(hr) << endl;
}
But if Error Lookup HRESULT_CODE(hr)==3705 gives the following msg "Bad or missing LAN Manager root directory." --- this doesnt make a lot of sense coz it's a local SQL server and previous statements all executed with good HRESULT==S_OK
norm
|
|
|
|
|
sorry, for error = 3705, Error Lookup yeilds "Message Not Found"
oops
norm
|
|
|
|
|
how can u enumerate tables given a database?
btw, we use ADO for database access. and we use SQL server.
thanks!
norm
|
|
|
|
|
Read my article called MSDEGUI - the queries I use there should work for you. It's in the new list on the main page.
No, I don't remember them, or I'd just tell you
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
just scan yr article briefly. isnt it for .NET?
anyway, i'm building all my code with VC6 - lots of anti microsoft types here in this company.
anyway, i am thinking, perhaps I can read MyDB.Tables.sysobjects
there're three columns of interests:
a. "names" -- object name: a simple string
b. "id" -- object id: just a simple integer
c. "xtype" and code as follows:
Object type. Can be one of these object types:
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
L = Log
FN = Scalar function
IF = Inlined table-function
P = Stored procedure
PK = PRIMARY KEY constraint (type is K)
RF = Replication filter stored procedure
S = System table
TF = Table function
TR = Trigger
U = User table
UQ = UNIQUE constraint (type is K)
V = View
X = Extended stored procedure
So, I will just count and retrieve an array of names (names - column one of sysobjects table) for all entries where xtype==U
norm
|
|
|
|
|
norm wrote:
just scan yr article briefly. isnt it for .NET?
Yes, so ? The query remains the same, all that changes is the layer that is talking to SQL Server.
norm wrote:
anyway, i'm building all my code with VC6 - lots of anti microsoft types here in this company.
Has no-one told them it comes from Microsoft ? :P
norm wrote:
anyway, i am thinking, perhaps I can read MyDB.Tables.sysobjects
I suspect that is exactly what I did in the article I pointed you to.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
thanks chris. and i hope that there'll be a day when it's no longer hip just being an anti microsoft. it's so stupid.
norm
|
|
|
|
|
If that day comes, it will be the day after Solaris penetrates 90% of the market.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
just remember in addition to cursor type, u can also specify whether you want server side cursor or client side cursor isnt it?
can u tell me where I should read up in this regard?
norm
|
|
|
|
|
Dunno, a book on ADO ? O'Reilley have a good one, from memory.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Simple solution - use OpenSchema method of ADO Connection object:
pConn->OpenSchema(adSchemaTables,vParams)
where vParams is a Safearray containing the following null, schema_name, null, null. This then returns a recordset which contains all of the tables in the schema. To enumerate the fields of a table, use similar:
m_pConn->OpenSchema(adSchemaColumns, vParams)
where vParams contains null, schema_name, table_name, null. Again returns recordset that can be used to get all sorts of information.
If you need a fuller example, fell free to e-mail me. vParams cna be used to control the operation in a much more detailed way than here, but this provides basic naming information.Also, has the advantage that will work with any DB type (SQLServer, Oracle, Access etc).
Hope it helps
|
|
|
|
|
Hi, I have an CEdit control which can be resized. The user can switch from a single line edit control to a multi line control if he decides so.
How do I detect the number of lines (a CEdit can hold not actually has)? I need to catch the switch from a single - to multi line layout and change some atributes.
Thanks
|
|
|
|
|
|
Do you mean visible lines in the edit control? There is no limit to the number of lines a control can have upto the 64K byte limit of \r\n pairs 63336/2 = 32768 possible lines held.
If its just the number of lines the control could display without a scrollbar, then you can compute this by gettting the client area size of the control, the DC and the font, and then count the number of lines like this:
int ComputeLines(int ID)
{
CWnd *pWnd = GetDlgItem(ID) ;
if (!pWnd)
return 0;
CEdit *pEdit = static_cast<CEdit*>(pWnd);
if (!pEdit)
return 0 ;
CDC *pDC = pEdit->GetDC() ;
CFont *pFont = pEdit->GetFont();
CFont *pOldFont = pDC->SelectObject(pFont);
CRect rect ;
pEdit->GetCLientRect(&rect);
CSize size = pDC->GetTextExtent("A", 1);
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
return rect.Height() / size.cy;
}
OK, the above it untested and types directly so, it may, may not work correctly
Roger Allen
Sonork 100.10016
I have a terminal disease. Its called life!
|
|
|
|
|
Roger Allen wrote:
If its just the number of lines the control could display without a scrollbar, then you can compute this by gettting the client area size of the control, the DC and the font, and then count the number of lines like this:
thousand thanks, Roger!
|
|
|
|
|
PS: instead of GetDC/ReleaseDC I might better use a CClientDC(this) , which is an MFC encapsulation of this AFAIK.
|
|
|
|
|
Just came across this. Very good sample collection on connection string format, just want to share it with u all:
http://www.able-consulting.com/MDAC/ADO/Connection/OLEDB_Providers.htm#OLEDBProviderForSQLServer
And to moderator:
is it possible that u put a similar tutorial on your site? It's very handy and will be very helpful later on.
Thanks.
norm
norm
|
|
|
|
|
|
I have a background in my CListCtrl. I don't want it to scroll though. How does one stop that from happening? Thanks for any help.
|
|
|
|
|
Repaint the background everytime you do any scroll event, perhaps?
But you'll need to double buffer your painting to prevent flicker I think!
Perhaps not much for help this but anyway...
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
I was wondering if anyone here has had any experience with using Waitable timers.
I am in the process of writing a scheduler, similar to SQL Server's Job scheduling utility. The reason i need it is because SQL server doesn't meet all of my criterias.
Now, I have been reviewing various ways of scheduling jobs and I posted earlier on this topic, except for it got buried under various other posts.
I was wondering whether Waitable Timers or TimerQueues are good candidates for a scheduling device? I guess what I would be doing is create all these timers for every job scheduled and then waitonmultiple objects. And I guess my WaitOnMulitple object parameter must be set to true, to allow things to go through as soon as they are signalled.
So, are there any issues and problems that these two suffer from?
thanks
|
|
|
|
|