这个C#程序没有显示任何输出..为什么? [英] this C# program is not showing any output..why?

查看:131
本文介绍了这个C#程序没有显示任何输出..为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System.Data.Sql;
using System;

class Program
{
    static void Main()
    {
        // Retrieve the enumerator instance and then the data.
        SqlDataSourceEnumerator instance =
          SqlDataSourceEnumerator.Instance;
        System.Data.DataTable table = instance.GetDataSources();

        // Display the contents of the table.
        DisplayData(table);

        Console.WriteLine("Press any key to continue.");
        Console.ReadKey();
    }

    private static void DisplayData(System.Data.DataTable table)
    {
        Console.WriteLine("Inside DisplayData");
        foreach (System.Data.DataRow row in table.Rows)
        {
            foreach (System.Data.DataColumn col in table.Columns)
            {
                Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
            }
            Console.WriteLine("============================");
        }
    }
}

推荐答案

您的代码正确,您是否启动了SQL Server?
您可以通过SQL Server Management Studio连接到任何实例吗?之后您会编写代码吗?
我看到该软件显示的唯一信息不是按任意键继续".是因为找不到SQL实例.
Your code is correct, have you started SQL server?
Can you connect to any instance via SQL server management studio? Does you code work afterwards?
The only reason I can see that that software would not show more than "Press any key to continue." is if no SQL instances hgave been found.


由于这段代码在我的环境中运行良好,因此可能有两个原因:
Since this piece of code worked quite well in my environment there could be a couple of reasons:

  1. 不耐烦:请耐心等待一分钟甚至两分钟.
  2. 由于网络限制,发现无法正常工作.
  3. 没有要查找的SQL Server.
  4. >

  1. Impatience: Just wait a minute or maybe even two.
  2. Discovery doesn''t work due to network constraints.
  3. There are no SQL Servers to discover.



问候,

Manfred



Regards,

Manfred


下面的代码对我有用


Below code works for me


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;

namespace CP_329450_this_Csharp_program_is_not_showing_any_output_why
{
    class Program
    {
        static void Main()
        {
            // Retrieve the enumerator instance and then the data.
            SqlDataSourceEnumerator instance =
              SqlDataSourceEnumerator.Instance;
            System.Data.DataTable table = instance.GetDataSources();

            // Display the contents of the table.
            DisplayData(table);

            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }

        private static void DisplayData(System.Data.DataTable table)
        {
            foreach (System.Data.DataRow row in table.Rows)
            {
                foreach (System.Data.DataColumn col in table.Columns)
                {
                    Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
                }
                Console.WriteLine("============================");
            }
        }
    }
}



但是通常会花一些时间来浏览所有sql服务器实例.

你可以试试:
1)启动导入/导出向导
2)尝试下拉源连接组合框.
3)看看需要多少时间.上面的代码需要花费相同的时间.

如果您进行调试,您将知道它会在
停止



But will useally take time to browse all sql server instances.

You can try :
1) start import / export wizard
2) try to drop down source connection combo box.
3) and see how much time it will take. The same time above code will take.

If you debug you will know it will halt at

System.Data.DataTable table = instance.GetDataSources();


这条线.


希望这会有所帮助,然后接受并投票回答
--Rahul D.


this line.


Hope this helps if yes then accept and vote the answer
--Rahul D.


这篇关于这个C#程序没有显示任何输出..为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆