Solved

How can I access msysobjects from a VC app

Posted on 1998-05-16
5
271 Views
Last Modified: 2013-11-20
I need to list the objects contained in an ms access db from my VC app. I've tried just about everything but can't seem to get it to work. I get security errors when I try to "select * from msysobjects" using either odbc or dao. However, I can access this table from inside ms access. Is there no way to use this table outside of access???
0
Comment
Question by:RGreene
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
tma050898 earned 100 total points
ID: 1311623
You are getting the errors because even Admin doesn't have read priveleges to the catalog tables. Is there any way you can set the priveleges for the database. IOW, if your app is accessing the db, I assume that it is db under your control. When does the db get created and how.

If you are creating the db, maybe you can give Admin read priveleges from within Access. If your program is creating the db, maybe you can copy the new db from a "template db" that has the Admin account set up with read privileges on this table.

HTH,
Tom
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1311624
RGreene,

Did the answer above help you or do I need to provide some additional information?

If the answer above did solve your problem, could you please close it by accepting the answer and grading my help? That way, other programmers having the same problem will have the benefit of this question having been asked and answered.

Thanks,
Tom
0
 

Author Comment

by:RGreene
ID: 1311625
Can you expound on how to copy the file from a "template file"???
0
 
LVL 3

Expert Comment

by:tma050898
ID: 1311626
RGreene,

For example, in our application what we did was the following...

1. Create an empty MS Access db

2. Change the permissions so that admin has read priveleges to the msysobjects table

3. Create a user-defined resource using the Access db...

4. At runtime, when you create your db you can then use code similar to the following in order to load the access db resource and create an access db on disk...
HRSRC hRsrc;
if (NULL != (hRsrc = ::FindResource(AfxGetInstanceHandle(), MAKEINTRESOURCE(YOUR_RESOURCE_ID), RT_RCDATA)))
{
 HGLOBAL hResource = ::LoadResource(AfxGetInstanceHandle(), hRsrc);

 LPVOID pVoid = ::LockResource(hResource);
 DWORD dwResourceSize = ::SizeofResource(AfxGetInstanceHandle(), hRsrc);  

 CFile fileReportsDatabaseTemplate;
 CFileException e;

 if (fileReportsDatabaseTemplate.Open(_T("YOUR DATABASE NAME"), CFile::modeCreate | CFile::modeWrite, &e ))
 {  
  // file was created
  fileReportsDatabaseTemplate.Write(pVoid, dwResourceSize);
  fileReportsDatabaseTemplate.Close();    
 }
}

5. At this point, the database file will exist and you can access it via within your application. You can also now run your queries against the msysobjects table.

BTW, I prefer keeping the template file as an embedded resource for the simple reason that I didn't want to take a chance on the end-user accidentally deleting this file. This way, I never have to worry about that, nor do I have to worry about versioning issues when I ship out another version of our product.

Tom

0
 

Author Comment

by:RGreene
ID: 1311627
I didn't go with your idea on using the resource file, but the other information was what I needed. Thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 117
iSeries DB2 Query 2 95
EvenOdd challenge 10 108
noX challenge 17 117
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question