Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. display the list of access database names in a combobox

display the list of access database names in a combobox

Scheduled Pinned Locked Moved C#
database
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MemberDotNetting
    wrote on last edited by
    #1

    i want to display the list of access database names in a combobox, i get an exception

    public static List GetDataBasesNames(string datasource)
    {
    cnx = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + datasource);
    cnx.Open();

                List DtataBaseNames = new List();
                OleDbCommand cmd = new OleDbCommand ("SELECT Name FROM MSysObjects WHERE Name Not Like 'MSys\*' AND (Type In (1,4,6))  ORDER BY Name", cnx);
                OleDbDataReader   rd = cmd.ExecuteReader();// Can not read records; no read permission on 'MSysObjects'.
                while (rd.Read())
                {
                    DtataBaseNames.Add(rd.GetString(0));
                }
              return  DtataBaseNames;
            }
    
    B K 2 Replies Last reply
    0
    • M MemberDotNetting

      i want to display the list of access database names in a combobox, i get an exception

      public static List GetDataBasesNames(string datasource)
      {
      cnx = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + datasource);
      cnx.Open();

                  List DtataBaseNames = new List();
                  OleDbCommand cmd = new OleDbCommand ("SELECT Name FROM MSysObjects WHERE Name Not Like 'MSys\*' AND (Type In (1,4,6))  ORDER BY Name", cnx);
                  OleDbDataReader   rd = cmd.ExecuteReader();// Can not read records; no read permission on 'MSysObjects'.
                  while (rd.Read())
                  {
                      DtataBaseNames.Add(rd.GetString(0));
                  }
                return  DtataBaseNames;
              }
      
      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      Seems the exception message already tells you what to do (set read permissions to whatever you're logging in as on that system table).

      M 1 Reply Last reply
      0
      • B BobJanova

        Seems the exception message already tells you what to do (set read permissions to whatever you're logging in as on that system table).

        M Offline
        M Offline
        MemberDotNetting
        wrote on last edited by
        #3

        how can i do this?

        B 1 Reply Last reply
        0
        • M MemberDotNetting

          i want to display the list of access database names in a combobox, i get an exception

          public static List GetDataBasesNames(string datasource)
          {
          cnx = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + datasource);
          cnx.Open();

                      List DtataBaseNames = new List();
                      OleDbCommand cmd = new OleDbCommand ("SELECT Name FROM MSysObjects WHERE Name Not Like 'MSys\*' AND (Type In (1,4,6))  ORDER BY Name", cnx);
                      OleDbDataReader   rd = cmd.ExecuteReader();// Can not read records; no read permission on 'MSysObjects'.
                      while (rd.Read())
                      {
                          DtataBaseNames.Add(rd.GetString(0));
                      }
                    return  DtataBaseNames;
                  }
          
          K Offline
          K Offline
          Karthik Harve
          wrote on last edited by
          #4

          Hi, Try by changing your query to this..

          select name from sys.databases

          If this has not worked properly, show the exception message.

          with regards Karthik Harve

          M 1 Reply Last reply
          0
          • M MemberDotNetting

            how can i do this?

            B Offline
            B Offline
            BobJanova
            wrote on last edited by
            #5

            Through your database configuration environment ... something like GRANT READ ON (table name) TO (user name), but I'm not a DBA expert (I usually set up database users through a host's web interface because my requirements are simple).

            1 Reply Last reply
            0
            • K Karthik Harve

              Hi, Try by changing your query to this..

              select name from sys.databases

              If this has not worked properly, show the exception message.

              with regards Karthik Harve

              M Offline
              M Offline
              MemberDotNetting
              wrote on last edited by
              #6

              i want to display the list of access database names in a combobox, i get an exception public static List GetDataBasesNames() { cnx = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0");// how I can connect to Access without specifying the database, I want to retrieve all the names of databases cnx.Open(); List DtataBaseNames = new List(); OleDbCommand cmd = new OleDbCommand ("SELECT Name FROM sys.database", cnx); OleDbDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { DtataBaseNames.Add(rd.GetString(0)); } return DtataBaseNames; }

              B L D 3 Replies Last reply
              0
              • M MemberDotNetting

                i want to display the list of access database names in a combobox, i get an exception public static List GetDataBasesNames() { cnx = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0");// how I can connect to Access without specifying the database, I want to retrieve all the names of databases cnx.Open(); List DtataBaseNames = new List(); OleDbCommand cmd = new OleDbCommand ("SELECT Name FROM sys.database", cnx); OleDbDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { DtataBaseNames.Add(rd.GetString(0)); } return DtataBaseNames; }

                B Offline
                B Offline
                BobJanova
                wrote on last edited by
                #7

                Repeating your OP verbatim is not helpful.

                1 Reply Last reply
                0
                • M MemberDotNetting

                  i want to display the list of access database names in a combobox, i get an exception public static List GetDataBasesNames() { cnx = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0");// how I can connect to Access without specifying the database, I want to retrieve all the names of databases cnx.Open(); List DtataBaseNames = new List(); OleDbCommand cmd = new OleDbCommand ("SELECT Name FROM sys.database", cnx); OleDbDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { DtataBaseNames.Add(rd.GetString(0)); } return DtataBaseNames; }

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  MemberDotNetting wrote:

                  how I can connect to Access without specifying the database, I want to retrieve all the names of databases

                  You don't. What you are trying to do is not possible to do with an Access database. Access databases are individual files and are not hosted in a server like SQL Server.

                  Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

                  1 Reply Last reply
                  0
                  • M MemberDotNetting

                    i want to display the list of access database names in a combobox, i get an exception public static List GetDataBasesNames() { cnx = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0");// how I can connect to Access without specifying the database, I want to retrieve all the names of databases cnx.Open(); List DtataBaseNames = new List(); OleDbCommand cmd = new OleDbCommand ("SELECT Name FROM sys.database", cnx); OleDbDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { DtataBaseNames.Add(rd.GetString(0)); } return DtataBaseNames; }

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    You can't do that. There is no such thing as an Access Database Server that maintains a list of every database registered with it. That's not how Access works. Access is a desktop file-based database. Every database is its own seperate entity. There is no such table of databases anywhere. The only way to do what you want is to search the hard drive for files ending in the supported extensions. That list varies depending on which version of Access is installed on the users machine.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups