---
title: "Listing the Databases connected to the DataSource"  
description: "In  this blog, I have discussed how to list all the Databases in SQL Server  connected to a Data Source in C# Windows Forms.  Namespaces  to be includ"  
author: "Shankar M"  
published: 2013-02-19  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/447/listing-the-databases-connected-to-the-datasource  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Listing the Databases connected to the DataSource

In this blog, I have discussed how to list all the [Databases](https://www.mindstick.com/startup/34/airbyte-the-open-source-platform-simplifying-data-integration-for-warehouses-lakes-and-databases) in [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server) [connected](https://www.mindstick.com/articles/12941/link-building-and-search-engine-rankings-how-are-they-connected) to a [Data Source](https://www.mindstick.com/interview/808/what-is-a-data-source) in C# [Windows](https://www.mindstick.com/articles/311752/how-to-install-and-use-the-google-wifi-software-on-a-windows-or-mac-computer) Forms.\

[Namespaces](https://www.mindstick.com/forum/155583/what-are-namespaces-in-c-sharp) to be included to [connect to SQL](https://www.mindstick.com/forum/34203/cannot-connect-to-sql-server) [Server Database](https://www.mindstick.com/forum/155643/how-to-create-sql-server-database-in-google-cloud):

```
using System.Data;
using System.Data.SqlClient;
```

Add a [ListView](https://www.mindstick.com/articles/12744/listview-in-android) control to the Form.

Copy the code snippet to the Windows Form Load event:

```
     //Substitute your connection string below in ConnectionString         String ConnectionString =           "Data Source=L04WEBMET001\\MSSQL2005;User id = LG_MssDev; password=LG@Dev765;";        //The Using Keyword frees all the resources managed by the Connection
automatically        using(SqlConnection Sqlconn = new SqlConnection(ConnectionString))        {            Sqlconn.Open();            //Get Schema Method returns the Schema Information for the DataSource that is
Specified            DataTable dtDbs = Sqlconn.GetSchema("Databases");            Sqlconn.Close();            //Columns.Add Method adds a column to the listView1 control            listView1.Columns.Add("Databases");            //Setting the listView1 View property to the Enumeration Details            listView1.View= View.Details;            //Fixing the Column Width property to 70           
listView1.Columns[0].Width = 70;            //Setting the listView1 GridLines property to true to show Grid appear between
rows and Columns            listView1.GridLines = true;             foreach(DataRow row in dtDbs.Rows)            {                //Use Items.Add Method of listView1 to add string to the
collection                
listView1.Items.Add(row["database_name"].ToString());            }        }
```

Thanks for reading.

---

Original Source: https://www.mindstick.com/blog/447/listing-the-databases-connected-to-the-datasource

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
