View Single Post
  #3 (permalink)  
Old August 19th, 2014, 08:58 PM
olo-B olo-B is offline
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: Chapter 14 - Unable to list DB from the given sample program.

For anyone else who ran into this problem.
I too ran into the same problem and realized that it had to do with the named instance on my computer. what I did was to concatenate the server name and instance name in the combobox items. Like this:
 foreach (DataRow row in dbTable.Rows)
                SqlSL = new clsSqlServerList();
                serverName = row[0].ToString();
cmbServer.Items.Add(serverName +"\\" + row["InstanceName"])
Also you could use the following console application code to list SQL server instances:
Hope this helps. Good luck!

using System.Data;

using System.Data.Sql;

using System;

public class ListSqlInstances

    public static int Main(string[] args)

        SqlDataSourceEnumerator sqldatasourceenumerator1 = SqlDataSourceEnumerator.Instance;

        DataTable datatable1 = sqldatasourceenumerator1.GetDataSources();

        foreach (DataRow row in datatable1.Rows)


            Console.WriteLine("Server Name:" + row["ServerName"]);

            Console.WriteLine("Instance Name:" + row["InstanceName"]);

            Console.WriteLine("Is Clustered:" + row["IsClustered"]);

            Console.WriteLine("Version:" + row["Version"]);

        return 1;