C # obtain the names of all SQL Server database instances

Source: Internet
Author: User
/// <Summary> /// obtain the names of all database instances with the specified IP address. /// </Summary> /// <Param name = "ip"> specifies the IP address. </Param> /// <Param name = "username"> username used to log on to the database. </Param> /// <Param name = "password"> password used to log on to the database. </Param> /// <returns> Returns a list of data instance names. </Returns> private arraylist getalldatabase (string IP, string username, string password) {arraylist dbnamelist = new arraylist (); sqlconnection connection = new sqlconnection (string. format ("Data Source = {0}; initial catalog = Master; user id = {1}; Pwd = {2}", IP, username, password )); datatable dbnametable = new datatable (); sqldataadapter adapter = new sqldataadapter ("Select name from master .. sysdatabases ", connection); lock (adapter) {adapter. fill (dbnametable);} foreach (datarow row in dbnametable. rows) {dbnamelist. add (row ["name"]);} return dbnamelist ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.