-
April 23rd, 2004, 03:42 PM
#1
ODBC newbie
Hello all,
i started my first database programming with vc++ and ODBC using Access as my database.
my first application is an address book which allow me to read ,write and delete the record.it's work fine on my machine(which i used for compile it).
But when i copied the .exe and the resources to another computer i couldn't run my application.
here are my question:
1-why i can't run my application on other machine?
2-how can i make other machine can run my application(i also attached the database file with the application)?
please help telling me about this.because i am a newbie i think it needs some other stuffs or technology to make it runs but i really don't know.
any reply would be appriciated.
-
April 23rd, 2004, 03:56 PM
#2
-
April 23rd, 2004, 06:20 PM
#3
How are your settings for the MFC Library ? Take a look at Main menu->Project->Settings
Shared or Static ? You will need to set it to static, but this will blow up your exe size.
This is just a guess, till you define "cant run".
Sonu
-
April 23rd, 2004, 08:34 PM
#4
yes, you must tell us the error you run your .exe
Another possible problem is that you may use ODBC Data Source Administrator to add a data source and use this source in your program. But when you move your application to another machine. There isn't the data source file (NOT the data file), so It said it can't find the data source.
There is two way to resolve this problem. one is to copy the data source file to the target machine and put it in a proper folder. the other is not to use data source file and write the database opening parameter string yourself.
-
April 24th, 2004, 09:13 AM
#5
my error
hello all,
when i ran my application on other machine it poped a message read "can't find MFC42D.DLL when trying to open my application".
To Sonu Kapoor: yes i have checked my project again and found out that i used shared library and when i choose static and recompile my project again it work fine but yes, like what you said my .exe file become more than 2Mb. thank you for that.
To olin: yes i used odbc adminstrator to add a data source and use it from my application.
There is two way to resolve this problem. one is to copy the data source file to the target machine and put it in a proper folder
i attached that data with my .exe file too but it still can't run.
the other is not to use data source file and write the database opening parameter string yourself.
can you plz tell me in more detail about this?i am really interesting in opening database parameter by myself may be i can reduce the size of my .exe file.
any reply would be appreciated.
thank you guys for helping me.
-
April 24th, 2004, 09:41 AM
#6
actrually, the database source file is just a file containing some information of the database file, so you can give these information without this file when opening a database. Here is some code from one of my program, maybe you can find something:
CString szCurDir;
::GetCurrentDirectory(256, szCurDir.GetBuffer(256));
szCurDir.ReleaseBuffer();
CString szConnect = _T("ODBC;DBQ=");
szConnect += szCurDir + _T("MyData.mdb;DefaultDir=")
+ szCurDir + _T(";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;");
if(!m_dbCD.OpenEx(szConnect), CDatabase::noOdbcDialog))
return FALSE;
good luck!
Last edited by olin; April 25th, 2004 at 09:36 AM.
-
April 24th, 2004, 10:43 AM
#7
any detail plz
hello olin,
thnak you for your code.
i read and understand what is your code do.but you know i am a newbie and i don't understand where to put you code in my application.
suppose i make a new SDI project do i have to choose "database view with file support "?
any reply would be apreciated
-
April 25th, 2004, 09:27 AM
#8
yes, you may use "database view with file support " or other styles. But no matter what you use, you should create a CDatabase object before you use your database file. If you have registered a database source file in ODBC Data Source Administrator, you may open the database as below:
CString szConnect = _T("DSN=MyDataSource");
if(!m_dbCD.OpenEx(szConnect), CDatabase::noOdbcDialog)
return FALSE;
but you can also manage your database file without a data source file. an example has been in my last thread.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|