display the list of access database names in a combobox
-
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; }
-
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; }
-
Seems the exception message already tells you what to do (set read permissions to whatever you're logging in as on that system table).
how can i do this?
-
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; }
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
-
how can i do this?
-
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
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; }
-
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; }
-
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; }
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
-
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; }
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