大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
sqlserver服务器名“主机名+\SQLEXPRESS” \ 后面的是实例名。
创新互联自2013年起,先为宜阳等服务建站,宜阳等地企业,进行企业商务咨询服务。为宜阳企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
一般情况下SQL使用默认实例,就可以不用写,直接使用主机名就可以了。但sqlexpress版本是强制使用了实例名,实例名就是sqlexpress。
在SQLServer上得到客户端信息(操作的数据库名,计算机名,用户名,网卡物理地址,IP地址,程序名)
create proc p_getlinkinfo
@dbname sysname=null,--要查询的数据库名,默认查询所有数据库的连接信息
@includeip bit=0--是否显示IP地址,因为查询IP地址比较费时,所以增加此控制
as
declare @dbid int
set @dbid=db_id(@dbname)
create table #tb(id int identity(1,1),dbname sysname,hostname nchar(128),loginname nchar(128),net_address nchar(12),net_ip nvarchar(15),prog_name nchar(128))
insert into #tb(hostname,dbname,net_address,loginname,prog_name)
select distinct hostname,db_name(dbid),net_address,loginame,program_name from master..sysprocesses
where hostname'' and (@dbid is null or )
if @includeip=0 goto lb_show --如果不显示IP地址,就直接显示
declare @sql varchar(500),@hostname nchar(128),@id int
create table #ip(hostname nchar(128),a varchar(200))
declare tb cursor local for select distinct hostname from #tb
open tb
fetch next from tb into @hostname
while @@fetch_status=0
begin
set @sql='ping '+@hostname+' -a -n 1 -l 1'
insert #ip(a) exec master..xp_cmdshell @sql
update #ip set where hostname is null
fetch next from tb into @hostname
end
update #tb set net_ip=left(a,patindex('%:%',a)-1)
from #tb a inner join (
select hostname,a=substring(a,patindex('Ping statistics for %:%',a)+20,20) from #ip
where a like 'Ping statistics for %:%') b on a.hostname=b.hostname
lb_show:
select id,数据库名=dbname,客户机名=hostname,用户名=loginname
,网卡物理地址=net_address,IP地址=net_ip,应用程序名称=prog_name from #tb
GO
//显示所有本机的连接信息:
exec p_getlinkinfo
//显示所有本机的连接信息,包含ip地址:
exec p_getlinkinfo @includeip=1
//显示连接指定数据库的信息:
exec p_getlinkinfo @dbname=表名,@includeip=1
在安装好后服务器,并安装SQL Server软件后,如果需要修改主机名,除了修改注册表里面的东西外,还需要通过如下方式修改SQL Server认到的主机名
sp_dropserver 'PCName1'
sp_addserver 'PCName2','local'
本地的主机名也可以通过select * from sys.servers 来查看。
更详细的信息
-- Run on SQL 2000 after server name change.
-- To correct the sysservers system table. Note the following excerpt from online help about remote users and logins:
-- If the computer has any remote logins, for example, if it is a
-- replication Publisher or Distributor, sp_dropserver may generate
-- an error similar to this:
-- Server: Msg 15190, Level 16, State 1, Procedure sp_dropserver, Line 44
-- There are still remote logins for the server 'SERVER1'.
-- To resolve the error, you may need to drop remote logins for this server.
-- If replication is installed, disable replication on the server before
-- running the sp_dropserver stored procedure.
-- Side note:
--
--SQL Books Online is slightly incorrect with regard to sp_addserver when renaming a server. The correct syntax is
-- exec sp_addserver 'NEWSERVERNAME', 'local'
--
-- If you do it the way it is specified in books online, the server is added with a new server id which is an identity field.
-- If you try to replicate from (and possibly to) this server, replication setup will fail because it is looking for a server
-- with an ID of 0 which won't be there. For some reason it uses this to determine something about the local computer
-- and bombs.
exec sp_dropserver old servername
go
exec sp_addserver new servername', 'local'
go
-- To correct orginating server on JOBS: If this isn't done, the jobs on
-- the server can't be edited, SQL thinks they came from another server
update msdb.dbo.sysjobs
set originating_server = 'new servername'
where originating_server = 'old servername'
go