Link to home
Start Free TrialLog in
Avatar of pratimag
pratimag

asked on

Connecting to a database

How do I connect to a database(.mdb) through Windows CE programming??

I tried with CeOpenDatabase
and CCeDBDatabase cdb; cdb.Open(...)
I am not able to connect to the exixting database.

Any hints or points regarding this will be helpful.
Avatar of mikecr
mikecr
Flag of United States of America image

What program are you trying to open it with? If it's not Access, you need to have some type of ODBC driver installed to access the database.
Don't know that much about CE and its DB components and the Language you are using however most of the times you need to create the object you are going to use before you can have access to it. In this case I am not talking about the actual database .mdb file but the Database object in your code.

Something to the affect of.
CreateObject.DBComponent.

I have no idea of the actual syntax but you should be able to find reference to it somewhere.
Here you go From the MSDN Library

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceobjst/htm/cerefcecreatedatabase.asp


BEGIN ARTICLE

Microsoft Windows CE .NET  

CeCreateDatabase
This function creates a new database. This function is obsolete. Applications should call CeCreateDatabaseEx2 instead.

A RAPI version of this function exists, and it is also named CeCreateDatabaseEx (RAPI).

CEOID CeCreateDatabase(
LPWSTR lpszName,
DWORD dwDbaseType,
WORD wNumSortOrder,
SORTORDERSPEC *rgSortSpecs
);
Parameters
lpszName
[in] Long pointer to a null-terminated string that specifies the name for the new database. The name can have up to 32 characters, including the terminating null character. If the name is too long, it is truncated and the database is created. Do not use an empty string as the database name.
dwDbaseType
[in] Specifies the type identifier for the database. This is an application-defined value that can be used for any application-defined purpose. For example, an application can use the type identifier to distinguish address book data from to-do list data or use the identifier during a database enumeration sequence. For more information, see CeFindFirstDatabase. The type identifier is not meant to be a unique identifier for the database. The system does not use this value.
wNumSortOrder
[in] Number of sort orders active in the database, with four being the maximum number. This parameter can be zero if no sort orders are active. If this value is zero, then the database engine creates a default sort order where rgSortSpecs[0].propid = 0. This is only a placeholder and does not influence the insertion order of the records.
rgSortSpecs
[in] Pointer to an array of actual sort order descriptions. The size of the array is specified by wNumSortOrder. This parameter can be NULL if wNumSortOrder is zero.
Return Values
The object identifier of the newly created database, not a handle to an open database, indicates success. NULL indicates failure. To get extended error information within a Windows CE program, call GetLastError. The following table lists possible values for GetLastError.

Value Description
ERROR_DISK_FULL The destination source does not contain enough space to create the new database.
ERROR_INVALID_PARAMETER A parameter was invalid.
ERROR_DUP_NAME A database already exists with the specified name.

Remarks
Because sort orders increase the system resources needed to perform each insert and delete operation, keep the number of sort orders to a minimum. Use the CeSetDatabaseInfo function to change the sort order later.

Requirements
Runs on Versions Defined in Include Link to
Windows CE OS 1.01 and later Windbase.h Winbase.h Coredll.lib

See Also
CeCreateDatabaseEx, CeCreateDatabaseEx2, CeDeleteDatabaseEx, CeOidGetInfoEx, CeOpenDatabaseEx, CeSetDatabaseInfoEx, GetLastError, SORTORDERSPEC

COPYRIGHT NOTICE. Copyright 2002 Microsoft Corporation, One Microsoft Way, Redmond, Washington 98052-6399 U.S.A. All rights reserved.
 
END  ARTICLE




And notice here that it says that the CeOpenDatabase  function is obsolete

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceobjst/htm/cerefCeOpenDatabase.asp

BEGIN ARTICLE

Microsoft Windows CE .NET  

CeOpenDatabase
This function opens an existing database. This function is obsolete. Applications should call CeOpenDatabaseEx2 instead.

A RAPI version of this function exists, and it is also called CeOpenDatabaseEx (RAPI).

HANDLE CeOpenDatabase(
PCEOID poid,
LPWSTR lpszName,
CEPROPID propid,
DWORD dwFlags,
HWND hwndNotify
);
Parameters
poid
[in] Pointer to the object identifier of the database to be opened. To open a database by name, set the value pointed to by poid to zero to receive the object identifier of the newly opened database when a database name is specified for lpszName.
lpszName
[in] Pointer to the null-terminated string that contains the name of the database to be opened. This parameter is ignored if the value pointed to by poid is nonzero.
propid
[in] Property identifier of the key for the sort order in which the database is to be traversed. All subsequent calls to CeSeekDatabase assume this sort order. This parameter can be zero if the sort order is not important.
dwFlags
[in] Specifies a bitmask of action flags. It is one of the values listed in the following table.
Value Description
CEDB_AUTOINCREMENT Causes the current seek position to be automatically incremented with each call to the CeReadRecordProps function.
0 The current seek position is not incremented with each call to CeReadRecordProps.

hwndNotify
[in] Handle to the window to which notification messages (DB_CEOID_*) will be posted if another thread modifies the specified database while it is open. This parameter can be NULL if you do not need to receive notifications.
Return Values
The handle to the open database indicates success. INVALID_HANDLE_VALUE indicates failure. To get extended error information, call GetLastError. The following table lists possible values for GetLastError.

Value Description
ERROR_INVALID_PARAMETER A parameter was invalid.
ERROR_FILE_NOT_FOUND No database exists with the specified name. This value applies only if the value pointed to by poid was set to NULL when the function was called.
ERROR_NOT_ENOUGH_MEMORY No memory was available to allocate a database handle.

Remarks
Use the CloseHandle function to close the handle returned by the CeOpenDatabase function.

Unlike many other traditional databases, opening and closing a database does not imply any transactioning. In other words, the database is not committed at the closing  it is committed after each individual call.

An application that opens the same database more than once and requests to be notified about changes to the database will receive change notification for changes that its process has made on the database. The reason is that change notification process is not done on a process level, but on a per open database level.

Requirements
Runs on Versions Defined in Include Link to
Windows CE OS 1.01 and later Windbase.h Winbase.h Coredll.lib

See Also
CeCloseHandle, CeCreateDatabase, CeOpenDatabaseEx (RAPI), CeOpenDatabaseEx, CeSeekDatabase, CeOpenDatabaseEx2, GetLastError

COPYRIGHT NOTICE. Copyright 2002 Microsoft Corporation, One Microsoft Way, Redmond, Washington 98052-6399 U.S.A. All rights reserved.
 
END  ARTICLE
Oops never mind the CeCreateDatabase actually creates a new Database. I misread the information. Sorry. Also which version Of CE are you programming for?
ASKER CERTIFIED SOLUTION
Avatar of HDWILKINS
HDWILKINS

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ITsheresomewhere
ITsheresomewhere

  ***Request for Closing Action and Input *****  

Hi pratimag and participating Experts

The reason for contacting you is that your help is needed in closing this question
and bringing the queue up to date. pratimag, you will also be returning the courtesy
that Experts extended to you in responding to the original question.

Your choices are:

1. Select a comment which provided you with the solution or information needed to
 resolve the question.

2. Request a split of points among participating Experts by stating in a comment
which experts and in what amount each is to be awarded.   A Moderator will handle
the closing awards.   You may designate as many Experts as you wish.

Example 100 point question:

Please Split points to  (Expert1name) - 50 points, (Expert2name)- 50 points


3. Request the question be Closed and PAQ for 0 points if you resolved it yourself,
 or if no solution was found.

To do this go to https://www.experts-exchange.com/commspt/   
Post a 0 point question, requesting closing assistance.  Include your reasoning
and a reference to this question - copy and paste this question URL shown above.

Please also post your comment here as to why to inform the participating Experts.

I realize that two and three are a bit of a bother, but it is necessary and simplification
is in the works.

Experts-Exchange really does appreciate your cooperation.

Again thanks    - DO NOT ACCEPT THIS COMMENT AS THE ANSWER


ITsheresomewhere
EE Database Cleanup Volunteer


EXPERTS - Please monitor this question in the event that additional information or
clarification is needed by the Asker.  Your assistance in bringing this question to a
close is, as always, greatly appreciated.
          *****If you have closing suggestions please make them now. *****
Hello pratimag,

It appears that you have abandoned this question as you have with more than 50% of all your questions.

I will ask Community Support to close it unless you finalize it within 7 days.  I will suggest to:

    DELETE this question - Abandoned No Refund No PAQ.

EXPERTS: Post a comment if you think somebody deserves credit here!

Please do not accept this comment as your answer!
==========
ITsheresomewhere
EE Database Cleanup Volunteer
Honestly, I think my answer was the correct answer.  You can't open an MDB on a CE.  You must use a CDB.

Harry
Yeah I agree with Harry
Thank you for both providing additional comments.

It would be extremely helpful if these comments could be placed at the time of the initial followup.  That is why the text specifically addressed to the Experts is included.  It may even assist the Asker in directly acting when the asker, even provided acurate information, is still incapable of making a fair decision.

The one significant element I missed was the askers inclusion of "cdb" in the question which would indicate at least some knowledge that further validates HDWilkins position.  

Since there is now concurrence I will modify the recommendation as follows:

            Award question to HDWILKINS and PAQ

Again, I thank you both for your input and ask your assistance in providing same at the initial followup.

ITsheresomewhere
EE DBCleanup Volunteer
Thanks,

I'm not sure that I saw your first message (maybe I did and maybe I didn't) but I've made this suggestion before to other moderators and I'll replay it:  

If you could put your intentions in your first message, we'd be better able to respond to it.  i.e. Its an old question and if I don't hear from you, I'm going to give points to, or delete it or whatever.  That way, we know what your thinking.  Not only would we have something to look at, you'd have a record of your intentions in the posting when you go back to it the second time.  

Harry
Per recommendation, force-accepted.

Netminder
CS Moderator