If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > accesing MSysObjects via C#

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-09, 14:36
yurako yurako is offline
Registered User
 
Join Date: Dec 2009
Posts: 1
Red face accesing MSysObjects via C#

Hey Guys,

I am using C# and access 2007.

I am trying to to figure out whether a certain table exists in the access 2007 database.

This is the query I am using:

SELECT MSysObjects.Name, MSysObjects.Type
FROM MSysObjects
WHERE (MSysObjects.Name="MyTablName") AND (MSysObjects.Type=1);

When run from the database, it operates fine.

However, when I run it from C#, I get the "no read permission on 'MSysObjects'' error.

I tryied to change permissions, but could find where there are in access 2007.

What should I do?

p.s as I saw in other forums, I do NOT want to rewrite the code in VB or any other language. I only know C#.

Thanks!
Reply With Quote
  #2 (permalink)  
Old 12-31-09, 02:33
jbedson jbedson is offline
Registered User
 
Join Date: Dec 2009
Posts: 46
I did a quick search for the error message and found something that may help.
It's in VB so I'll translate it for you. I also had to change it from the original a little to work.
Here is a link to the original artical
An Error Has Occurred - ASP.NET Forums

Here is the code:

Code:
        public bool getTables(string tableName)
        {
            bool tableExists = false;
            OleDbConnection conn = new OleDbConnection(conStr);
            conn.Open();
            DataTable dt = conn.GetSchema("Tables");
           
            conn.Close();

            foreach (DataRow row in dt.Rows)
            {
                if (row.ItemArray[2].ToString() == tableName)
                {
                    tableExists = true;
                    break;
                }

          }
            return tableExists;
      }
I got this to work.. Hope it helps

Jim
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On