How to get archive-informations of database with SQLClient or ODBC

G

Guest

I have used blow method to get archive-informations of database,but there is always error,i
don't know,how can i do,with ODBC too.I use J

[C#
SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")

SqlDataAdapter schemaDA = new SqlDataAdapter("SELECT * FROM INFORMATION_SCHEMA.TABLES "
"WHERE TABLE_TYPE = 'BASE TABLE' "
"ORDER BY TABLE_TYPE",
nwindConn)

DataTable schemaTable = new DataTable()
schemaDA.Fill(schemaTable);
 
M

Miha Markic

Hi,

The code provided works just fine.
You are probably experiencing connection problems.
What kind of error do you get?

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

wg said:
I have used blow method to get archive-informations of database,but there is always error,i
don't know,how can i do,with ODBC too.I use J#


[C#]
SqlConnection nwindConn = new SqlConnection("Data
Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
 
G

Guest

There are 2 errors,1 System-error,2 can't find file c:\....\INFORMATION_SCHEMA.mdb
I use Access database and connect database with "Microsoft OLE DB Provider for ODBC Drivers".I think that error is from the SQL query"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_TYPE
but i don't know,where.Thanks!
 
M

Miha Markic

Errr, now, I am confused.
In example you provided you were using SqlServer.
If you use Access database then the sql statament won't work because it is
SqlServer specific.
Try this statament instead:
SELECT MSysObjects.Name FROM MSysObjects
WHERE ((MSysObjects.Type = 1) AND Not (([MSysObjects].[Name] Like "MSys*")
Or ([MSysObjects].[Name] Like "~*")))

--
Miha Markic - DXSquad/RightHand .NET consulting & software development
miha at rthand com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to (e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous postings.
wg said:
There are 2 errors,1 System-error,2 can't find file c:\....\INFORMATION_SCHEMA.mdb.
I use Access database and connect database with "Microsoft OLE DB Provider
for ODBC Drivers".I think that error is from the SQL query"SELECT * FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY
TABLE_TYPE"
 
G

Guest

OK!it works.and could you tell me ,what's the SQL Statament,if i connect a database with ODBC . Is there a method or SQL Statament,with it i can get Archive-Informations of a database,no matter which database or connection-method i use.Thanks!
 
M

Miha Markic

Hi,

You'll have to use AdoX.dll activeX object.(Microsoft ADO Ext. 2.* for DDL
and Security) if you want an uniform way.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

wg said:
OK!it works.and could you tell me ,what's the SQL Statament,if i connect a
database with ODBC . Is there a method or SQL Statament,with it i can get
Archive-Informations of a database,no matter which database or
connection-method i use.Thanks!
 
M

Miha Markic

Uh, almost forgot. There is a managed way, too:

Check out OleDbConnection.GetOleDbSchemaTable Method.

To retrieve all tables you might use (from .net help file):

public DataTable GetTables(OleDbConnection conn)
{
conn.Open();
DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new object[] {null, null,
null, "TABLE"});
conn.Close();
return schemaTable;
}

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

wg said:
OK!it works.and could you tell me ,what's the SQL Statament,if i connect a
database with ODBC . Is there a method or SQL Statament,with it i can get
Archive-Informations of a database,no matter which database or
connection-method i use.Thanks!
 
G

Guest

yes,i know this (OleDbConnection.GetOleDbSchemaTable) Method and i get connectionString from Data Link Properties Dialog.this method(OleDbConnection.GetOleDbSchemaTable),it functions only for Microsoft Jet 4.0 OLE DB Provider
for example if i want to connect a database with Microsoft OLE DB Provider for ODBC Drivers,then it doesn't work.There is a error,too: OLE DB of .Net Framework doesn't support ODBC Drivers,please use ODBC of .Net Framework .i use ado 2.7 Thank you very much
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top