在SQL Server的数据库维护过程中,有时候在一些特殊情况下需要在单用户模式下启动SQL Server实例。 下面总结一下单用户模式启动SQL Server的几种方式:

1:命令模式(sqlservr.exe)启动

首先在命令窗口中切换到Binn目录(这个要视SQL Server实际安装路径情况而定,另外,多实例情况下,必须切换到对应路径),如果你对sqlservr.exe命令不熟悉,可以查看相关帮助信息。如下所示:

C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Binn>sqlservr.exe /?

usage: sqlservr

        [-a<L2 buffer pool directory>,<size in GB>]       (adding an L2 buffer pool file)

        [-c] (not as a service)

        [-d file] (alternative master data file)

        [-l file] (alternative master log file)

        [-e file] (alternate errorlog file)

        [-f] (minimal configuration mode)

        [-m] (single user admin mode)

        [-g number] (stack MB to reserve)

        [-k <decimal number>] (checkpoint speed in MB/sec)

        [-n] (do not use event logging)

        [-s name] (alternate registry key name)

        [-T <number>] (trace flag turned on at startup)

        [-x] (no statistics tracking)

        [-y number] (stack dump on this error)

        [-B] (breakpoint on error (used with -y))

        [-K] (force regeneration of service master key (if exists))

        [-v] (list version information)

 

See documentation for details.

2018-04-06 11:28:00.52             SQL Server shutdown has been initiated

sqlservr.ex启动时,当前环境有多实例,而你有没有指定参数-s,那么就会提示类似如下信息, 需要你指定-s参数的SQL Server服务名称。

C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Binn>sqlservr.ex

e -c -m

2018-04-06 11:40:54.15 Server      Multiple instances of SQL server are installe

d on this computer. Renter the command, specifying the -s parameter with the nam

e of the instance that you want to start.

2018-04-06 11:40:54.16 Server      SQL Server shutdown has been initiated

sqlservr.exe -c -m  -s{instancename}

sqlservr.ex启动时,如果SQL Server服务本身还在运行,就会报“Operating system error = 32(The process cannot access the file because it is being used by another process.).

C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Binn>sqlservr.ex

e -c -m -sMSSQLSERVER

2018-04-06 11:41:59.01 Server      Error: 17058, Severity: 16, State: 1.

2018-04-06 11:41:59.01 Server      initerrlog: Could not open error log file 'C:

\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Log\ERRORLOG'. Ope

rating system error = 32(The process cannot access the file because it is being

used by another process.).

2018-04-06 11:41:59.32 Server      Error: 17058, Severity: 16, State: 1.

2018-04-06 11:41:59.32 Server      initerrlog: Could not open error log file 'C:

\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Log\ERRORLOG'. Ope

rating system error = 32(The process cannot access the file because it is being

used by another process.).

2018-04-06 11:42:02.04 Server      SQL Server shutdown has been initiated

如果在sqlservr.exe当中退出单用户模式,直接使用CTRL+C 或 CTRL + Break,如下所示:

 

2:命令模式(net star)启动

C:\Users>net stop mssqlserver

The following services are dependent on the SQL Server (MSSQLSERVER) service.

Stopping the SQL Server (MSSQLSERVER) service will also stop these services.

SQL Server Agent (MSSQLSERVER)

Do you want to continue this operation? (Y/N) [N]: y

The SQL Server Agent (MSSQLSERVER) service is stopping.

The SQL Server Agent (MSSQLSERVER) service was stopped successfully.

The SQL Server (MSSQLSERVER) service is stopping.

The SQL Server (MSSQLSERVER) service was stopped successfully.

C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Binn>net start mssqlserver /m

The SQL Server (MSSQLSERVER) service is starting.

The SQL Server (MSSQLSERVER) service was started successfully.

3:SQL Server配置管理器启动

在SQL Server配置管理器中,找到对应实例,右键单击属性,在启动参数里面增加参数-m,然后重启即可。

在单用户模式下启动SQL Server实例时,请注意下列事项:

·         只有一个用户可以连接到服务器。

·         不执行CHECKPOINT 进程。 默认情况下,启动时自动执行此进程。

在单用户模式下启动 SQL Server 可使计算机本地 Administrators 组的任何成员作为 sysadmin 固定服务器角色的成员连接到 SQL Server 实例。 有关详细信息,请参阅在系统管理员被锁定时连接到 SQL Server

在单用户模式下, 只有一个用户可以连接到服务器,那么这样问题就来了,很有可能当你需要登录的时候,这个唯一的的用户已经被其它用户捷足先登了。此时你却被拒之门外,是否相当抓狂。此时你可能遇到下面错误

C:\Users>sqlcmd

Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login failed for user '

xxxx'. Reason: Server is in single user mode. Only one administrator c

an connect at this time..

SSMS客户端一般遇到下面这样的错误信息:

Login failed for user 'xxxx'. Reason: Server is in single user mode. Only one administrator can connect at this time. (Microsoft SQL Server, Error: 18461)

错误日志或命令里面输出的日志,你会看到类似如下信息:

2018-04-06 12:21:14.85 Logon       Error: 18461, Severity: 14, State: 1.

2018-04-06 12:21:14.85 Logon       Login failed for user 'xxx'. Reason: Server is in single user mode. Only one administrator can connect at this time. [CLIENT: 192.168.xxx.xxx]

在这种情况下,怎么办呢? 难道要拼速度? 当然不是,你需要从下面这些方面注意:

在单用户模式下连接到SQL Server实例之前,停止SQL Server Agent 服务;否则 SQL Server Agent 服务将使用该连接,从而使其阻塞。

在单用户模式下启动SQL Server实例时,SQL Server Management Studio 可以连接到 SQL Server。 但是Management Studio中的对象资源管理器可能会失败,因为在某些操作中它需要使用多个连接。 若要在单用户模式下管理 SQL Server,可以执行 Transact-SQL 语句(仅通过 Management Studio 中的查询编辑器连接)或者使用 sqlcmd 实用工具。

当您将 -m 选项与 sqlcmd 或 Management Studio 结合使用时,可以将连接限制为指定的客户端应用程序。 例如,-m"sqlcmd" 将连接限制为单个连接并且该连接必须将自身标识为 sqlcmd 客户端程序。 当您正在单用户模式下启动 SQL Server 并且未知的客户端应用程序正在占用这个唯一的可用连接时,使用此选项。 若要通过 Management Studio 中的查询编辑器进行连接,请使用 -m"Microsoft SQL Server Management Studio - Query"。

如下所示,如果你指定了单用户只能以SQLCMD连接,那么此时,其它通过SSMS等其它方式连接数据库都会报上面错误,其它通过程序连接过来的连接就不会抢占这个连接了。

C:\Windows\system32>net stop mssqlserver

The SQL Server (MSSQLSERVER) service is stopping.

The SQL Server (MSSQLSERVER) service was stopped successfully.

C:\Windows\system32>net start mssqlserver /m"SQLCMD"

The SQL Server (MSSQLSERVER) service is starting.

The SQL Server (MSSQLSERVER) service was started successfully.

C:\Windows\system32>

如果你指定参数/m"Microsoft SQL Server Management Studio - Query" 那么就会阻止像应用程序或SQLCMD登录,如下所:

C:\Windows\system32>net stop mssqlserver

The SQL Server (MSSQLSERVER) service is stopping.

The SQL Server (MSSQLSERVER) service was stopped successfully.

C:\Windows\system32>net start mssqlserver /m"Microsoft SQL Server Management Studio - Query"

The SQL Server (MSSQLSERVER) service is starting.

The SQL Server (MSSQLSERVER) service was started successfully.

C:\Users>sqlcmd

Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login failed for user '

xxx'. Reason: Server is in single user mode. Only one administrator c

an connect at this time..

单用户模式启动SQL Server实例总结的更多相关文章

  1. SQL server已经设置为单用户模式,Sql server还原失败数据库正在使用,无法获得对数据库的独占访问权

    如果已经设置为单用户模式,还是报这个错误的话,就按照一下SQL执行就

  2. 专用管理连接(DAC)和单用户模式

    数据库运维人员,在维护数据库时,有时会遇到一些特殊的情况,例如,SQL Server实例无法访问,此时需要用到管理员在紧急情况下专用的连接:有时,在做一些系统级别的配置修改时,当前数据库不能被其他用户 ...

  3. SQL server已经设置为单用户模式,还是无法做分离、属性设置等操作

    https://www.cnblogs.com/xingyunqiu/p/10336938.html SQL server已经设置为单用户模式,Sql server还原失败数据库正在使用,无法获得对数 ...

  4. SQL SERVER的单用户模式以及专用管理员连接

    2007-03-08 18:22:03.46 server    Microsoft SQL Server  2000 - 8.00.2039 (Intel X86) May  3 2005 23:1 ...

  5. 最小配置启动SQL SERVER,更改SQL Server最大内存大小导致不能启动的解决方法

    如果存在配置问题而无法启动服务器,则可以使用最小配置启动选项来启动 Microsoft SQL Server 实例. 这就是启动选项 -f. 使用最小配置启动 SQL Server 实例会自动将服务器 ...

  6. 修改sql server实例、数据库、表、字段的排序规则

    转自:http://blog.51cto.com/jimshu/1095780 概念与详情请参考:字符编码与排序规则:https://www.cnblogs.com/gered/p/9145123.h ...

  7. Linux学习之CentOS(二十二)--单用户模式下修改Root用户的密码

    在上一篇随笔里面详细讲解了Linux系统的启动过程 (Linux学习之CentOS(二十一)--Linux系统启动详解),我们知道Linux系统的启动级别一共有6种级别,通过 /etc/inittab ...

  8. centos7.2进入单用户模式

    1 - 在启动grub菜单,选择编辑选项启动 2 - 按键盘e键,来进入编辑界面 3 - 找到Linux 16的那一行,将ro改为rw init=/sysroot/bin/sh 4 - 现在按下 Co ...

  9. 在Linux 中进入单用户模式的技巧

    在这篇简短的文章中,我们将向你介绍在 SUSE 12 Linux 中进入单用户模式的步骤.在排除系统主要问题时,单用户模式始终是首选.单用户模式禁用网络并且没有其他用户登录,你可以排除许多多用户系统的 ...

随机推荐

  1. sql server 索引阐述系列五 索引参数与碎片

    -- 创建聚集索引 create table [dbo].[pub_stocktest] add constraint [pk_pub_stocktest] primary key clustered ...

  2. Android--Activity中使用Intent传值

    Intent,又称为意图,是一种运行时绑定机制,它能在程序运行的过程中链接两个不同的组件(Activity.Service.BroadcastReceiver).通过Intent,程序可以向Andro ...

  3. 全网最详细的最新稳定OSSEC搭建部署(ossec-server(CentOS6.X)和ossec-agent(CentOS6.X))(图文详解)

    不多说,直接上干货! 前言 写在前面的话,网上能够找到一些关于ossec方面的资料,虽然很少,但是总比没有强,不过在实际的使用过程中还是会碰到许多稀奇古怪的问题.整理整理我的使用过程,就当做一篇笔记吧 ...

  4. 全网最详细的一个超级好用的命令行工具【Cmder】的安装之后的一些配置(图文详解)

    不多说,直接上干货! 1.修改命令提示符λ为$ 首先,我们看到 进入解压后的cmder的目录,进入vendor,打开init.bat文件. 修改第15行的代码 @prompt $E[;;40m$P$S ...

  5. 不得不提的volatile及指令重排序(happen-before)

    微信公众号[程序员江湖] 作者黄小斜,斜杠青年,某985硕士,阿里 Java 研发工程师,于 2018 年秋招拿到 BAT 头条.网易.滴滴等 8 个大厂 offer,目前致力于分享这几年的学习经验. ...

  6. Python GUI之tkinter窗口视窗教程大集合(看这篇就够了)

    一.前言 由于本篇文章较长,所以下面给出内容目录方便跳转阅读,当然也可以用博客页面最右侧的文章目录导航栏进行跳转查阅. 一.前言 二.Tkinter 是什么 三.Tkinter 控件详细介绍 1. T ...

  7. MySQL 5.6的一个bug引发的故障

    突然收到告警,提示mysql宕机了,该服务器是从库.于是尝试登录服务器看看能否登录,发现可以登录,查看mysql进程也存在,尝试登录提示 ERROR (HY000): Too many connect ...

  8. python练习四—简单的聊天软件

    python最强大的是什么?库支持!!有了强大的库支持,一个简单的聊天软件实现就更简单了,本项目思路如下 # 项目思路 1. 服务器的工作 * 初始化服务器 * 新建一个聊天房间 * 维护一个已链接用 ...

  9. LINUX负载均衡LVS-NAT搭建

    1.搭建前的规划工作 这里从lvs官方网站找了一个nat模型的图,如下: 我这里使用虚拟机模拟出了4台rhel6机器.一台服务器作为lvs调度器(40网段使用的都是仅主机模式,168网段使用桥接模式) ...

  10. Map<String, Object>转Object,Object转 Map<String, Object>

    Map转Object import com.alibaba.fastjson.JSON; Map<String, Object> boneAgeOrderMap=boneAgeOrderS ...