获取本机SqlServer名称

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
using System.Data.Sql; 

//检索包含有关可用SQL Server实例的信息的表,必须先使用共享/静态Instance属性来检索枚举器
SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
//调用 GetDataSources 方法,返回包含可用服务器的相关信息的DataTable
System.Data.DataTable table = instance.GetDataSources();
//取出服务器名称
string servername=table.Rows[0]["ServerName"].ToString();

返回的table信息:

Column Description
ServerName Name of the server.
InstanceName Name of the server instance. Blank if the server is running as the default instance.
IsClustered Indicates whether the server is part of a cluster.
Version Version of the server. For example:
  • 9.00.x (SQL Server 2005)
  • 10.0.xx (SQL Server 2008)
  • 10.50.x (SQL Server 2008 R2)
  • 11.0.xx (SQL Server 2012)|

参考信息来源:(https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/enumerating-instances-of-sql-server?redirectedfrom=MSDN)

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: SQL SERVER