0

I am implementing a C# application which should extract from the sql server the metadata for all tables in the specific database.

Such question was already asked - it was required to do that from sql - SQL Server meta data table and column descrption . I don`t want to run any queries.

Does C# has a API for that?

There is a following approach : http://msdn.microsoft.com/en-us/library/ms254934(v=vs.110).aspx

Does the link above solve what I want to do?

In the example from the link - I get only one table? (but my requests is all database tables)as well where do I specify user credentials and database name?

Also I didn't find any reference about the performance of such execution?

For me it looks that it should be very effective to retrieve the schema if we really read only metadata from some source without executing a query

Community
  • 1
  • 1
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
  • You may wish to review the [post formatting guide](http://stackoverflow.com/editing-help). Remember, to create a new paragraph, hit enter twice. For a newline, hit enter once and indent with two spaces. Newlines without a two space indent aren't considered paragraph breaks. – Charles Feb 06 '14 at 18:07

1 Answers1

0

using (SqlConnection connection = new SqlConnection(@"Data Source=(local);Integrated Security=True;Initial Catalog=DB_Name;"))

{

connection.Open();

using (SqlCommand command = connection.CreateCommand()) {

command.CommandText =@"SELECT Name from Sysobjects where xtype = 'u'"; using (SqlDataReader reader = command.ExecuteReader()) {

while (reader.Read())

{ // your code goes here... } } } }`

Pradeep
  • 29
  • 4
  • Is there a way not to run query?why not to use SqlConnection.GetSchema Method – YAKOVM Feb 06 '14 at 14:29
  • SqlConnection.GetSchema will retrieve views and tables. If you need both views and tables and you can with Getschema method – Pradeep Feb 12 '14 at 12:04