探讨:如何查看和获取SQL Server实例名建站知识
导读:1建站知识本篇文章是对如何查看和获取SQL Server实例名进行了详细的分析介绍,需要的朋友参考下网站建设制作网站建设教程。
一、查看實例名時可用
1、服务—SQL Server(实例名),默认实例为(MSSQLSERVER)
或在连接企业管理时-查看本地实例
2、通過注冊表HKEY_LOCAL_MAseo网站优化CHINE/SOFTWARE/Microsoft/Microsoft SQL Server/InstalledInstance
3、用命令sqlcmd/osqlsqlcmd -Lsqlcmd -Lcosql -L
获取可用實例,以下舉一個例子,根據自己情況改
复制代码 代码如下:
DECLARE @Table TABLE ( instanceName sysname NULL)
insert @Table EXEC sys.xp_cmdshell 'sqlcmd -Lc'
--LEFT(@@serverName,CHARINDEX('/',@@serverName+'/')-1) 替代為本機名就行了 , 根據實例命名規則判斷
SELECT * FROM @Table WHERE instanceName LIKE LEFT( @@serverName , CHARINDEX ( '/' , @@serverName + '/' )- 1)+ '%'
二、--1. SELECT SERVERPROPERTY('InstanceName')
--2sp_helpserver
--3select @@SERVERNAME
--4SELECT * FROM SYS.SYSSERVERS
--5SELECT * FROM 网站seo优化SYS.SERVERS
三、
EXECUTE xp_regread @rootkey='HKEY_LOCAL_MACHINE',@key='SOFTWARE/Microsoft/Microsoft SQL Server/Instance Names/SQl',@value_name='MSSQLSERVER'
四、
Select CaseWhen SERVERPROPERTY ('InstanceName') Is Null Then @@SERVERNAMEElse SERVERPROPERTY ('InstanceName')End
五、在本地或网络得到所有实例名
1、You can do with registry reading , like my code
复制代码 代码如下:
using System;using Microsoft.Win32;
namespace SMOTest{ class Program { static void Main() { RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE/Microsoft/Microsoft SQL Server"); String[] instances = (String[])rk.GetValue("InstalledInstances"); if (instances.Length > 0) { foreach (String element in instances) { if (element == "MSSQLSERVER") Console.WriteLine(System.Environment.MachineName); else Console.WriteLine(System.Environment.MachineName + @"/" + element); } } } }}
2、You can use SQLDMO.dll to retrie网站建设多少钱ve the list of SQL Server instances. The SQLDMO.dll can be found from the "C:/Program Files/Microsoft SQL Server/80/Tools/Bin" folder. Refer this assembly in your project and the following snippet would return a List Object containing the sql server instances.复制代码 代码如下:
public static List GetSQLServerInstances() {NameList sqlNameList = null;Application app = null;
var sqlServers = new List();try {app = new ApplicationClass();sqlNameList = app.ListAvailableSQLServers();foreach (string sqlServer in sqlNameList)sqlServers.Add(sqlServer);}catch(Exception ex){//play with the exception.} finally {if (sqlNameList != null)sqlNameList = null;if (app != null)app = null;}return sqlServers;}
相关网站建设制作网站建设教程。声明: 本文由我的SEOUC技术文章主页发布于:2023-05-24 ,文章探讨:如何查看和获取SQL Server实例名建站知识主要讲述实例,标签,SQL网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_6550.html