Wednesday, 27 February 2013

Get All Databases in SQL Server in ASP.NET c#

Get All Databases in SQL Server in ASP.NET c#

If User wants to installed databases in the SQL Server Instance. user can get all databases using SQLConnection GetSchema Object.

> Add gridView to aspx page

<asp:GridView  Font-Names="'Times New Roman',roman" 
            Caption="<h3 STYLE='BACKGROUND:TEAL;COLOR:WHITE'>Using SqlConnection Get All Databases in ASP.NET</H3>"
            ID="GridView1" runat="server" Height="179px" Width="652px">
            <HeaderStyle BackColor="Teal" ForeColor="WhiteSmoke" />
        </asp:GridView>


> Query Database objects(Here  assumes master database default)

            SqlConnection conn = new SqlConnection(@"Data Source=localhost\sqlexpress2012;trusted_connection=yes;");
            conn.Open();
            DataTable schemaTable = conn.GetSchema("DATABASES");
            GridView1.DataSource = schemaTable;
            GridView1.DataBind();
 
 
> OUTPUT


Using SqlConnection Get All Databases in ASP.NET

database_namedbidcreate_date
master14/8/2003 9:13:36 AM
tempdb22/27/2013 2:19:13 PM
model34/8/2003 9:13:36 AM
msdb42/10/2012 9:02:17 PM
testee510/23/2012 8:16:28 PM
nopcommerce610/26/2012 8:36:56 AM
AdventureWorks2012710/26/2012 10:27:06 PM
pubs810/27/2012 9:00:25 AM
Northwind910/27/2012 9:02:20 AM

Tags:Get All Databases in SQL Server in ASP.NET c#,get all databases supported by SQL Server 2012, get All database names and DBID in asp.net C#, get Database Creation Date, get Database DBID, get database Name.