我试图确定我已经安装的sql server/sql express的实例(手动或编程),但所有的例子都告诉我运行一个sql查询来确定这假设我已经连接到一个特定的实例。
当前回答
如果您有兴趣在脚本中确定这一点,您可以尝试以下方法:
sc \\server_name query | grep MSSQL
注意:grep是gnuwin32工具的一部分
其他回答
安装的所有实例都应该显示在Microsoft管理控制台的服务管理单元中。如果需要获取实例名,请执行“开始|运行|类型的服务”。查找所有带有“Sql Server(实例名)”的条目。
在Windows命令行中输入:
SC \\server_name query | find /I "SQL Server ("
其中“server_name”是希望在其上显示SQL实例的任何远程服务器的名称。
当然,这需要足够的权限。
SQL Server浏览器服务http://msdn.microsoft.com/en-us/library/ms181087.aspx
SQL Server permits applications to find SQL Server instances within the current network. The SqlDataSourceEnumerator class exposes this information to the application developer, providing a DataTable containing information about all the visible servers. This returned table contains a list of server instances available on the network that matches the list provided when a user attempts to create a new connection, and expands the drop-down list containing all the available servers on the Connection Properties dialog box. The results displayed are not always complete. In order to retrieve the table containing information about the available SQL Server instances, you must first retrieve an enumerator, using the shared/static Instance property:
using System.Data.Sql;
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("============================");
}
}
}
来自MSDN http://msdn.microsoft.com/en-us/library/a6t1z9x2(v=vs.80).aspx
如果你在SSMS内,你可能会发现它更容易使用:
SELECT @@Version
推荐文章
- 我如何执行插入和返回插入的身份与Dapper?
- 索引中列的顺序有多重要?
- 如何清空SQL Server查询缓存?
- 在SQL Server中做嵌套case语句逻辑的最佳方法
- 从实体框架中删除单个记录?
- 使用SQL Server Server Management Studio导入/导出数据库
- 如何结合日期从一个字段与时间从另一个字段- MS SQL Server
- 在SQL中获取两个值的最小值
- 如何在不知道其名称的情况下删除SQL默认约束?
- 在表变量上创建索引
- 如何在SQL Server中删除外键?
- 如何为查询返回的每一行执行存储过程一次?
- 如果没有使用EXISTS引入子查询,则只能在选择列表中指定一个表达式
- SQL Server -事务回滚错误?
- 查询以列出数据库中每个表中的记录数量