Wednesday, March 9, 2011

Get Database Tables Schema using ADO.Net Connection

Functionality for reading Database tables' schema using ADO.Net connection

public DataTable GetTables(string strConnection)
     {
         //Create connectionstring
         SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(strConnection);
         SqlConnection con = null;
         DataTable dtTables = new DataTable();
         try
         {
             con = new SqlConnection(builder.ConnectionString);
             con.Open();
 
             //Get the Schema for the tables
             dtTables = con.GetSchema(SqlClientMetaDataCollectionNames.Tables, new string[] { null, null, null, "BASE TABLE" });
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             if (con != null)
             {
                 con.Dispose();
             }
         }
 
         return dtTables;
     }
Code can be downloaded here: Download

No comments:

Post a Comment

Access to XMLHttpRequest at 'from origin has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. .net core angular

Issue: The angular application was getting error from API that the origin has been blocked by CORS policy. Solution: Make sure that the...