|
Hi all,
I have generating a project like server-client communication using winsock. I would like to do that server application has keep connection to the database and retrieve some record set using CRecordset object from the database.
My questions are........
1) Can i write that CRecordset object into the file? after that can i read it from that file as a
CRecordset object? and send it to the client application.
2) If client application could retrieve the records from its retrieved CRecordset object?
If you know please tell me your suggestions and if you have any tutorials regarding to above the problem please lets me know
Thanks in Advance
regards
surezu
|
|
|
|
|
what you're after is called serialization.
as you're using MFC, CRecordset already inherits from CObject, which provides a base for serialized object.
read more on the msdn about CObject::Serialize()
|
|
|
|
|
now i'm know some more concepts in the serialization after reading MSDN document but i got some error in my following code snippet..........
<br />
1 void COBjSerializationDlg:: OnBnClickedDbw()<br />
2 {<br />
3 CString sIp,sDb,sPwd,sConn,sPort,sUn;<br />
4 sIp="192.168.2.17";<br />
5 sPort="5432";<br />
6 sPwd="fasp";<br />
7 try<br />
8 {<br />
9 sConn = "DRIVER={PostgreSQL ANSI};SERVER=" + sIp + ";port=" + sPort +<br />
";DATABASE=" + sPwd + ";UID=" + sPwd + ";PWD=" + sPwd + ";";<br />
10 db.OpenEx(sConn);<br />
11 }<br />
12 catch(CDBException *e)<br />
13 {<br />
14 MessageBox("Database Connection Refused."+e->m_strError,"DataBase<br />
15 Connection Error",MB_OK|MB_ICONERROR);<br />
16 e->Delete();<br />
17 }<br />
<br />
18 CRecordset rs(&db);<br />
<br />
19 rs.Open(AFX_DB_USE_DEFAULT_TYPE, "select name from master;");<br />
20 CFile file1;<br />
21 file1.Open("hexa.bin",CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);<br />
22 CArchive ar1(&file1,CArchive:: store);<br />
23 if(ar1.IsStoring())<br />
24 {<br />
25 CObject:: Serialize(ar1);<br />
26 ar1 << &rs;<br />
27 }<br />
28 ar1.Flush();<br />
29 ar1.Close();<br />
30 file1.Close();<br />
31 rs.Close();<br />
32 db.Close();<br />
33 }<br />
<br />
<br />
<br />
34 void COBjSerializationDlg:: OnBnClickedDbr()<br />
35 {<br />
36 CRecordset *set = new CRecordset();<br />
37 CFile file2;<br />
38 file2.Open("hexa.bin", CFile::modeRead| CFile::typeBinary);<br />
39 CArchive ar2(&file2,CArchive:: load);<br />
40 if(ar2.IsLoading())<br />
41 {<br />
42 CObject:: Serialize(ar2);<br />
43 ar2 >> set;<br />
44 }<br />
45 set.MoveFirst();<br />
46 int j;<br />
47 j = 0;<br />
48 CString s;<br />
49 while(set.IsEOF())<br />
50 {<br />
51 s = "";<br />
52 set.GetFieldValue (j,s);<br />
53 AfxMessageBox(s);<br />
54 set.MoveNext();<br />
55 }<br />
56 ar2.Flush();<br />
57 ar2.Close();<br />
58 set.Close();<br />
59 file2.Close();<br />
60 delete set;<br />
61 }
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'CRecordset *__w64 ' (or there is no acceptable conversion)
will be thrown during the compilation of the above code at LINE.NO:43
please help me.....what i did wrong in my snippet....
|
|
|
|
|
Regarding question 1 - You might want to try deriving from CRecordset, implementing a Serialize() function and saving your objects in a CArchive ...
|
|
|
|
|
now i'm know some more concepts in the serialization after reading MSDN Document but i got some error in my following code snippet..........
1 void COBjSerializationDlg:: OnBnClickedDbw()<br />
2 {<br />
3 CString sIp,sDb,sPwd,sConn,sPort,sUn;<br />
4 sIp="192.168.2.17";<br />
5 sPort="5432";<br />
6 sPwd="fasp";<br />
7 try<br />
8 {<br />
9 sConn = "DRIVER={PostgreSQL ANSI};SERVER=" + sIp + ";port=" + sPort +<br />
";DATABASE=" + sPwd + ";UID=" + sPwd + ";PWD=" + sPwd + ";";<br />
10 db.OpenEx(sConn);<br />
11 }<br />
12 catch(CDBException *e)<br />
13 {<br />
14 MessageBox("Database Connection Refused."+e->m_strError,"DataBase<br />
15 Connection Error",MB_OK|MB_ICONERROR);<br />
16 e->Delete();<br />
17 }<br />
<br />
18 CRecordset rs(&db);<br />
<br />
19 rs.Open(AFX_DB_USE_DEFAULT_TYPE, "select name from master;");<br />
20 CFile file1;<br />
21 file1.Open("hexa.bin",CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);<br />
22 CArchive ar1(&file1,CArchive:: store);<br />
23 if(ar1.IsStoring())<br />
24 {<br />
25 CObject:: Serialize(ar1);<br />
26 ar1 << &rs;<br />
27 }<br />
28 ar1.Flush();<br />
29 ar1.Close();<br />
30 file1.Close();<br />
31 rs.Close();<br />
32 db.Close();<br />
33 }<br />
<br />
<br />
<br />
34 void COBjSerializationDlg:: OnBnClickedDbr()<br />
35 {<br />
36 CRecordset *set = new CRecordset();<br />
37 CFile file2;<br />
38 file2.Open("hexa.bin", CFile::modeRead| CFile::typeBinary);<br />
39 CArchive ar2(&file2,CArchive:: load);<br />
40 if(ar2.IsLoading())<br />
41 {<br />
42 CObject:: Serialize(ar2);<br />
43 ar2 >> set;<br />
44 }<br />
45 set.MoveFirst();<br />
46 int j;<br />
47 j = 0;<br />
48 CString s;<br />
49 while(set.IsEOF())<br />
50 {<br />
51 s = "";<br />
52 set.GetFieldValue (j,s);<br />
53 AfxMessageBox(s);<br />
54 set.MoveNext();<br />
55 }<br />
56 ar2.Flush();<br />
57 ar2.Close();<br />
58 set.Close();<br />
59 file2.Close();<br />
60 delete set;<br />
61 }
error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'CRecordset *__w64 ' (or there is no acceptable conversion)
will be thrown during the compilation of the above code at LINE.NO:43
please help me.....what i did wrong in my snippet....
|
|
|
|
|
I think you should derive from CRecordset, and in the derived class implement the Serialize function where you will save/load the relevant data to/from the object. Then call your Serialize function directly - set.Serialize(ar).
That should do the trick ...
Hope this help.
|
|
|
|
|
It's much easier to make a class that represents a record and make that class serializable.
A CRecordset "represents a set of records selected from a data source". You can
probably come up with a way to serialize it but it will be complicated. To unserialize you
need to have the recordset ready to insert records...It can be done but it makes no sense on
the client end in a client/server situation.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Thank you for your suggestions.......
|
|
|
|
|
Hello all,
Which files should I copy into the other computer in order to be able to use an app made with VC++2005 in a computer without the development tools installed?
Thank you in advance.
|
|
|
|
|
You can download an exe file called vcredist_x86.exe from microsoft. This EXE copies all of the required MFC and VC DLLs to the proper locations ...
Just run the EXE as part of your setup.
If you have trouble find the EXE, let me know I'll email it to you ...
Hope this helps.
|
|
|
|
|
Great, it seems I need the MSI3.1, but I've just downloaded it and now it is installing.
Thank you.
|
|
|
|
|
I've done that, installed the MSI3.1, and then the vcredist, and after all the app continues without running.
Any idea? thank you in advance.
|
|
|
|
|
What is the error message you are receiving ?
|
|
|
|
|
You was not able to start the application because the configuration is not correct. Reinstall the application can solve the problem.
I've copied the exe directly and nothing else...
|
|
|
|
|
Oh, sorry, I probably didn't explain myself properly ...
You need to run the vcredist_x86.exe on the target PC (the one without the VC2005) so that it deploys the VC & MFC DLLs, and only then run your application.
|
|
|
|
|
Yes, this is what I've done... the strangest thing is that at the end the VCREDIST don't show any message...
and at the end, when I try to execute the programa the problem appears...
|
|
|
|
|
Is your app built in debug or release ?
If it's in Debug, then that's the problem ... the vcredist_x86.exe only deploys the release version of the required DLLs ... if your application is built in debug then it's dependant upon the debug versions of MFC/VC and they are probably missing. Try to deploy a release version of your app.
|
|
|
|
|
I've also tried that...
|
|
|
|
|
Maybe you have a lib that's compiled in debug in your application ?
|
|
|
|
|
No, I've even made a new solution, and tried to compile it in release mode. After doing that, the same result...
|
|
|
|
|
Hi,
Once I got it right to run an application, developed in VS2005 VC++ without having to run any external application, before hand. I linked statically to a couple of lib's. I cant remeber their names, but it worked.
Have a look at: C Run-Time Libraries (CRT)[^]
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
The best way is to create a setup project to install it, or run the .exe the others have told you about. There is a quick and dirty way that works on XP, you can just copy the .dll's that you want but you have to put them into directories with their manifests. For example, (from here[^])
to include Microsoft.VC80.MFC.dll you need to copy the \Microsoft.VC80.MFC directory from %VCINSTALLDIR%\redist\ into the loacl application directory like:
<br />
\bin\<br />
myApplication.exe<br />
\Microsoft.VC80.MFC<br />
This works on XP but I don't think it works on earlier OSs. Of course, ensure you have the release build, otherwise you would need the debug dlls.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Great! it worked! I still don't understand why do the two exes that everybody told me to use are not working on that computer, but who knows...
Thank you and everybody for your help.
|
|
|
|
|
I have application build in Embeded VC++ 4.0 project,now i want to include (.h) file in project which is produced from another (.exe) built in Win32(App) Console.I have added header file in project workspace.The problem is (.h) file is created after compiling the project.I want to include (.h) file before compilation of code because it is being used in project.Is there any way to do thing?
I have tried by writing command in Custom build step:
call "L:\11rvtsapril\ExcelCvt.exe"//(ExcelCvt.exe is Wn32 Console App)
Is there any way to change Comipler option so that Cosole App(.exe) runs first,after that compilation of Application take place.Thanks in advance.
priyank
|
|
|
|
|
pri_skit wrote: The problem is (.h) file is created after compiling the project
that's impossible !!!
the .obj, .lib, .dll or .exe are, but not .h, .c or .cpp because they are the SOURCE of a program !
|
|
|
|