|
Hello Everyone
I am trying to automate a database update (that involves some business logic) using a windows service. The constraints are that
1. I cannot write the service in .NET
Hence I opted to write the service as a C++ executable.
In the service, I have a call using ODBC API (ExecuteSQL method) to a SQL Server Stored procedure just before the call to Sleep method.
The problem is that the call to the stored proc to be executed does NOT work. But the Service installs/uninstalls/starts/stops fine.
If I strip off the code for the service and just run the ODBC part of it, it works fine.
I would like to know if there are issues that need to be taken into account if I make a ODBC call in an NT Service.
I will greatly appreciate any inputs on this.
Thanks
Anand
|
|
|
|
|
By default, a windows service is using the "local system" account, which does not have access to user settings (registry keys, odbc data sources, etc.). It is likely that your odbc data source is a "user" source instead of a "system" source. You need to configure it to "system" data source and you probably have to reboot the machine afterwards.
Good luck.
My articles and software tools
|
|
|
|
|
Hi All,
Need help regarding stored procedure concept using CDatabase & Crecordset database classes. I am working on MFC
application which supports all major RDBMS databases(SQL Server, MySQL, Oracle & MS-Access). I have to process thousands of records from a file and do insert operations.
Right now, this is what I am doing
1. Read one record from a file. Parse it and prepare query.
2. Executing it by using cDatabase's ExecuteSql() function.
But it is taking very long time to process thousand's of records. Every time database has to process the query and prepare an execution plan. That's the reason why I need to solve this problem by using stored procedures which should work with all the databases.
I appreciate if someone could help me in this regard.
Thanks,
Sridhar
|
|
|
|
|
Would using CRecordset::AddNew() and CRecordset::Update() be any faster? I've never directly used CDatabase::ExecuteSQL() to add rows to a table so I'm not sure which method would be more efficient.
You might want to give ExecuteSQL("BULK INSERT...") a look. If you can format your file to look like the table format, it just might work.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi David,
Did you have any example of Bulk Insert functionality? Does it work with all the databases?
Thanks,
|
|
|
|
|
Sridhar Sanikommu wrote:
Did you have any example of Bulk Insert functionality?
Possibly. Assuming the table looks like:
Name Type
---- ----
col1 char(3)
col2 int Create a file named mydata.txt that looks like:
abc,1;def,2;ghi,3; Load this file into the table with:
BULK INSERT <table name here>
FROM 'mydata.txt'
WITH
(DATAFILETYPE = 'char',
FIELDTERMINATOR = ',', ROWTERMINATOR = ';') Sridhar Sanikommu wrote:
Does it work with all the databases?
Having not used "all the databases," I couldn't possibly know.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi David,
I appreciate your quick response. This is the first time I posted my question in code project though I opened my account long time back(almost two years) and been following message board Q&A's. Especially, if I encounter responses from yourself, Micheal Dunn, Ravi, Prakash(you people are top of my head) etc I go through the techniques that you guys suggest.
Keep going....pass your knowledge and empower others.
BTW, do you have any generic database module(using CDatabase & CRecordset classes) which I can get?
Thanks,
Sridhar
|
|
|
|
|
I have a question regarding copying of whole compressed (DIVX) streams with the AVIFile API.
This code snippet copies the video stream to another file, but that file gets about 10 times bigger than the original. I guess the target stream is uncompressed, but the streaminfo explicitely states DIVX.
How can I copy streams from one file to the other without decompressing/compressing (direct stream copy)?
<br />
HRESULT hr=S_OK;<br />
<br />
PAVIFILE pSourceFile=NULL;<br />
PAVIFILE pTargetFile=NULL;<br />
<br />
PAVISTREAM pSourceStream=NULL;<br />
PAVISTREAM pTargetStream=NULL;<br />
<br />
AVISTREAMINFO streaminfo;<br />
BITMAPINFOHEADER bitmapinfo;<br />
<br />
AVIFileInit();<br />
<br />
hr=AVIFileOpen(&pSourceFile,"test_source.avi",OF_SHARE_DENY_WRITE,0L);<br />
if(FAILED(hr))<br />
...<br />
<br />
hr=AVIFileGetStream(pSourceFile,&pSourceStream,streamtypeVIDEO,0);<br />
if(FAILED(hr))<br />
...<br />
<br />
LONG bitmapinfosize=sizeof(bitmapinfo);<br />
hr=AVIStreamReadFormat(pSourceStream,0,&bitmapinfo,&bitmapinfosize);<br />
if(FAILED(hr))<br />
...<br />
<br />
hr=AVIStreamInfo(pSourceStream,&streaminfo,sizeof(streaminfo));<br />
if(FAILED(hr))<br />
...<br />
<br />
hr=AVIFileOpen(&pTargetFile,"test_target.avi",OF_CREATE|OF_WRITE,0L);<br />
if(FAILED(hr))<br />
...<br />
<br />
hr=AVIFileCreateStream(pTargetFile,&pTargetStream,&streaminfo);<br />
if(FAILED(hr))<br />
...<br />
<br />
hr=AVIStreamSetFormat(pTargetStream,0,&bitmapinfo,sizeof(bitmapinfo));<br />
if(FAILED(hr))<br />
...<br />
<br />
LONG lbuffersize=20000;<br />
BYTE* buffer;<br />
buffer=new BYTE[lbuffersize];<br />
<br />
LONG lPos=0;<br />
LONG lLen=0;<br />
for(long lPos=AVIStreamStart(pSourceStream);lPos<AVIStreamEnd(pSourceStream);lPos++)<br />
{<br />
hr=AVIStreamRead(pSourceStream,lPos,1,buffer,lbuffersize,&lLen,NULL);<br />
if(FAILED(hr))<br />
...<br />
<br />
DWORD dwFlag=0;<br />
if(AVIStreamIsKeyFrame(pSourceStream,lPos))<br />
dwFlag=AVIIF_KEYFRAME;<br />
<br />
hr=AVIStreamWrite(pTargetStream,lPos,1,buffer,lbuffersize,dwFlag,NULL,NULL);<br />
if(FAILED(hr))<br />
...<br />
}<br />
<br />
if(pTargetStream)<br />
AVIStreamRelease(pTargetStream);<br />
<br />
if(pTargetFile)<br />
AVIFileRelease(pTargetFile);<br />
<br />
if(pSourceStream)<br />
AVIStreamRelease(pSourceStream);<br />
<br />
if(pSourceFile)<br />
AVIFileRelease(pSourceFile);<br />
<br />
delete[] buffer;<br />
<br />
AVIFileExit();
using: [VISUAL STUDIO 6.0 sp5] [WIN98/2]
|
|
|
|
|
I'm using TerminateProcess to shut down explorer.exe (not iexplore.exe). This works, but a few seconds after explorer.exe is terminated, it starts back up. When I terminate explorer though the Windows Task Manager it doesn't restart itself.
I want to control when exporer.exe starts back up. How do I keep it from restarting itself?
(I can post my code if anyone thinks it's necessary.)
Thanks for the help!
Ian
|
|
|
|
|
haven't you ever noticed that when windows freezes and you have no desktop and no taskbar anymore, you can do "New task" (with Crtl+Alt+Del or Ctrl+Shift+Esc for example) and type in the field explorer...
i don't think the way you think is able to controle what you want.
TOXCCT >>> GEII power
|
|
|
|
|
I'm not sure I follow you. I want to shut down explorer.exe. This I have done (I can see it dissapear from the process list in Windows Task Manager).
Now I need to figure out how to keep it from starting itself back up. I know this is possible because I have seen other applications that shut it down and keep it down. I don't suppose they continually shut it down in a separate thread?
|
|
|
|
|
|
|
oooppss, didn't see that you had the answer
|
|
|
|
|
Hi,
i created a toolbar using CreateWindowEx() but i got no XP toolbar (im using xp).
how can i make it so?
|
|
|
|
|
I am not looking to create, rather I am more looking for advice on something to buy.
I would like to be able to scan in paper forms and use a tool to convert the image into a form that C++ can use.
If such a tool does not exist, can you point me towards a tool that would build HTML or other interface from a paper form.
thanks
|
|
|
|
|
I found that a word doc file can be saved as HTML.
But how can I save a HTML as a word DOC?
Any ideas? Thank you very much!
Alick
|
|
|
|
|
|
I have a question during providing services to some users.This product should get this result:First,push the button on the dialogue; then the excel form should appear;and last,when I choose any row, the data of this row can be read by the program.Anyone know how to achieve this function? Thanks!
|
|
|
|
|
From my experience I can tell you I've found two ways to read data from excel files, one is by adding the excel assembly reference to your project and creating an instance of the Excel application object, I suppose this would be the only way to actually 'show' the Excel grid programmatically, beware though, that this requires excel to be installed in any client executing you app. The other way is to use Extended Properties of the OleDbDataAdapter which allows you to get a range of cells or an entire worksheet into a DataTable, thereafter you can manipulate the data, show it in a datagrid or do whatever you need with it.
Chris.
|
|
|
|
|
Here an msdn search that will give you some articles/samples on doing this with ado.net's dataadapter:
http://search.microsoft.com/search/results.aspx?qu=excel+file+ado.net&View=msdn&st=b&c=0&s=1&swc=0
|
|
|
|
|
Hi,
im coding proper SDK now and i did a toolbar with couple of buttons, and each button got a BMP file that i created.
how can i add 24bit bmp and not only 8bit?
Avi
|
|
|
|
|
|
yeah, but everything is fine except that im coding only with SDK and no MFC.
do u know the exact way to do it bcuz i searched everywhere and nothing
|
|
|
|
|
I would have downloaded the sample for one of the toolbars, for example http://www.codeproject.com/docking/ctruecolortoolbar_update.asp[^]. Build the sample and singlestep - in this case it's the function LoadTrueColorToolBar that is interesting. Step into the MFC source, where you will see the underlying SDK calls. The main problem with MFC is not that it is complicated, rather that it is a far too thin wrapper of the SDK
|
|
|
|