如何在C#中获取远程sqlserver名称 [英] how to get remote sqlserver name in c#

查看:114
本文介绍了如何在C#中获取远程sqlserver名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在创建应用程序远程sqlserver数据库备份
所以我如何从C#中的网络获取所有sqlserver名称

我正在使用此代码
但是我只获得本地系统名称和实例名称,但是从网络上得到的只是服务器名称而不是实例名称,因此我无法连接到网络服务器,我已经允许remoteconnection和服务自动重启.

Hi
i am creating a application remote sqlserver database backup
so how can i get all sqlserver name from network in c#

i am using this code
but i am only geting local system name and instance name but from network i am geting only servername not instance name so i am not able to connect to network server i have allow remoteconnection and service automatily also restart.

SqlDataSourceEnumerator SqlEnumerator;
           SqlEnumerator = SqlDataSourceEnumerator.Instance;
           DataTable dTable = SmoApplication.EnumAvailableSqlServers(false);

           DataTable dTable = SqlEnumerator.GetDataSources();

           foreach (DataRow db in dTable.Rows)
           {
               comboBox1.Items.Add(db["ServerName"].ToString()+ "\\" + db["InstanceName"].ToString());
           }

推荐答案

我不确定是什么原因导致的,但是我已经亲眼目睹了这个问题.您是否实际尝试仅使用不带实例名称的服务器名称进行连接.我写了一个可以在我的工作中使用的应用程序.组合框用于显示网络上的可用SQL Server实例.尽管实际上每个人都看到"SERVER \ INSTANCE",但有一台计算机只显示网络上所有SQL Server的服务器名称.但是,如果该计算机的用户选择连接,它将正确连接.奇怪.
I''m not sure what causes this but I have seen this issue first-hand. Have you actually tried connecting using ONLY the server name without the instance name. I wrote an application which is used at my job. A combobox is used to display the available SQL Server instances on the network. While practically everyone sees "SERVER\INSTANCE", there is one computer which only displays the server name for all SQL Servers on the network. However, if that computer''s user chooses to Connect it will connect properly. Strange.


本文建议可以调用SP并返回名称;
http://sqldbpool.com/2008/09/03/how -to-change-sql-server-instance-name/ [
This article suggests its possible to call an SP and return the name;
http://sqldbpool.com/2008/09/03/how-to-change-sql-server-instance-name/[^]

Unconfirmed though........give it a try and feedback here :)


这篇关于如何在C#中获取远程sqlserver名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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