SQL Server Express CREATE DATABASE 权限在数据库“master”中被拒绝

2024-04-15

当我将选项更改为 UserInstance="False" 后,错误开始发生。

因为我想使用全文搜索,所以需要更改选项。但是,它停止工作了。有什么办法可以让它再次发挥作用吗?

我正在将应用程序池作为网络服务运行,并具有完全控制权。


  1. 从此下载脚本微软网站 http://archive.msdn.microsoft.com/addselftosqlsysadmin/
  2. 以管理员身份运行它
  3. 请按照说明和您的设置进行操作。

更新 9/3/2014

上面的 Microsoft URL 不再有效,有人花时间将其保存到 GitHubGist,链接如下https://gist.github.com/wadewegner/1677788 https://gist.github.com/wadewegner/1677788

更新 11/1/2021

下面是整个脚本,不记得在 2014 年能够做到这一点,我想这是 2021 年的福利之一。

    @echo off
    rem
    rem ****************************************************************************
    rem
    rem    Copyright (c) Microsoft Corporation. All rights reserved.
    rem    This code is licensed under the Microsoft Public License.
    rem    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
    rem    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
    rem    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
    rem    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
    rem
    rem ****************************************************************************
    rem
    rem CMD script to add a user to the SQL Server sysadmin role
    rem
    rem Input:  %1 specifies the instance name to be modified. Defaults to SQLEXPRESS.
    rem         %2 specifies the principal identity to be added (in the form "<domain>\<user>").
    rem            If omitted, the script will request elevation and add the current user (pre-elevation) to the sysadmin role.
    rem            If provided explicitly, the script is assumed to be running elevated already.
    rem
    rem Method: 1) restart the SQL service with the '-m' option, which allows a single connection from a box admin
    rem            (the box admin is temporarily added to the sysadmin role with this start option)
    rem         2) connect to the SQL instance and add the user to the sysadmin role
    rem         3) restart the SQL service for normal connections
    rem
    rem Output: Messages indicating success/failure.
    rem         Note that if elevation is done by this script, a new command process window is created: the output of this
    rem         window is not directly accessible to the caller.
    rem
    rem
    setlocal
    set sqlresult=N/A
    if .%1 == . (set sqlinstance=SQLEXPRESS) else (set sqlinstance=%1)
    if /I %sqlinstance% == MSSQLSERVER (set sqlservice=MSSQLSERVER) else (set sqlservice=MSSQL$%sqlinstance%)
    if .%2 == . (set sqllogin="%USERDOMAIN%\%USERNAME%") else (set sqllogin=%2)
    rem remove enclosing quotes
    for %%i in (%sqllogin%) do set sqllogin=%%~i
    @echo Adding '%sqllogin%' to the 'sysadmin' role on SQL Server instance '%sqlinstance%'.
    @echo Verify the '%sqlservice%' service exists ...
    set srvstate=0
    for /F "usebackq tokens=1,3" %%i in (`sc query %sqlservice%`) do if .%%i == .STATE set srvstate=%%j
    if .%srvstate% == .0 goto existerror
    rem
    rem elevate if <domain/user> was defaulted
    rem
    if NOT .%2 == . goto continue
    echo new ActiveXObject("Shell.Application").ShellExecute("cmd.exe", "/D /Q /C pushd \""+WScript.Arguments(0)+"\" & \""+WScript.Arguments(1)+"\" %sqlinstance% \""+WScript.Arguments(2)+"\"", "", "runas"); >"%TEMP%\addsysadmin{7FC2CAE2-2E9E-47a0-ADE5-C43582022EA8}.js"
    call "%TEMP%\addsysadmin{7FC2CAE2-2E9E-47a0-ADE5-C43582022EA8}.js" "%cd%" %0 "%sqllogin%"
    del "%TEMP%\addsysadmin{7FC2CAE2-2E9E-47a0-ADE5-C43582022EA8}.js"
    goto :EOF
    :continue
    rem
    rem determine if the SQL service is running
    rem
    set srvstarted=0
    set srvstate=0
    for /F "usebackq tokens=1,3" %%i in (`sc query %sqlservice%`) do if .%%i == .STATE set srvstate=%%j
    if .%srvstate% == .0 goto queryerror
    rem
    rem if required, stop the SQL service
    rem
    if .%srvstate% == .1 goto startm
    set srvstarted=1
    @echo Stop the '%sqlservice%' service ...
    net stop %sqlservice%
    if errorlevel 1 goto stoperror
    :startm
    rem
    rem start the SQL service with the '-m' option (single admin connection) and wait until its STATE is '4' (STARTED)
    rem also use trace flags as follows:
    rem     3659 - log all errors to errorlog
    rem     4010 - enable shared memory only (lpc:)
    rem     4022 - do not start autoprocs
    rem
    @echo Start the '%sqlservice%' service in maintenance mode ...
    sc start %sqlservice% -m -T3659 -T4010 -T4022 >nul
    if errorlevel 1 goto startmerror
    :checkstate1
    set srvstate=0
    for /F "usebackq tokens=1,3" %%i in (`sc query %sqlservice%`) do if .%%i == .STATE set srvstate=%%j
    if .%srvstate% == .0 goto queryerror
    if .%srvstate% == .1 goto startmerror
    if NOT .%srvstate% == .4 goto checkstate1
    rem
    rem add the specified user to the sysadmin role
    rem access tempdb to avoid a misleading shutdown error
    rem
    @echo Add '%sqllogin%' to the 'sysadmin' role ...
    for /F "usebackq tokens=1,3" %%i in (`sqlcmd -S np:\\.\pipe\SQLLocal\%sqlinstance% -E -Q "create table #foo (bar int); declare @rc int; execute @rc = sp_addsrvrolemember '$(sqllogin)', 'sysadmin'; print 'RETURN_CODE : '+CAST(@rc as char)"`) do if .%%i == .RETURN_CODE set sqlresult=%%j
    rem
    rem stop the SQL service
    rem
    @echo Stop the '%sqlservice%' service ...
    net stop %sqlservice%
    if errorlevel 1 goto stoperror
    if .%srvstarted% == .0 goto exit
    rem
    rem start the SQL service for normal connections
    rem
    net start %sqlservice%
    if errorlevel 1 goto starterror
    goto exit
    rem
    rem handle unexpected errors
    rem
    :existerror
    sc query %sqlservice%
    @echo '%sqlservice%' service is invalid
    goto exit
    :queryerror
    @echo 'sc query %sqlservice%' failed
    goto exit
    :stoperror
    @echo 'net stop %sqlservice%' failed
    goto exit
    :startmerror
    @echo 'sc start %sqlservice% -m' failed
    goto exit
    :starterror
    @echo 'net start %sqlservice%' failed
    goto exit
    :exit
    if .%sqlresult% == .0 (@echo '%sqllogin%' was successfully added to the 'sysadmin' role.) else (@echo '%sqllogin%' was NOT added to the 'sysadmin' role: SQL return code is %sqlresult%.)
    endlocal
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SQL Server Express CREATE DATABASE 权限在数据库“master”中被拒绝 的相关文章

  • SQL FORMAT 函数错误

    这个SQL select FORMAT lNum from rpt myView 产生以下错误 参数数据类型 varchar 对于格式的参数 1 无效 功能 lNum is a varchar 10 运行 SQL Server 2012 v
  • 查找 SQL Server 中表的 B 树高度

    由于数据库数据以B Tree的形式组织在8k页中 对于PK信息也是如此 数据库中的每个表都应该可以计算B Tree的高度 从而揭示达到某些数据需要多少次跳跃 由于行大小和 PK 大小都非常重要 因此很难计算 因为例如varchar 250
  • ELMAH 错误和经典 Asp

    我们已经在我们拥有的 ASP NET MVC 网站上使用 ELMAH 进行错误日志记录 但我们的主网站仍然是经典的 asp 我已经开始为该网站创建错误处理 日志记录结构 但我认为它如果我们能够在所有应用程序中保持错误日志记录的一致性 那就太
  • 不同提供商的相同 EDMX 文件

    我正在开发一个项目 其中有一个本地数据库 SQL CE 在不存在与服务器的连接的情况下用作缓冲区 在服务器上我想使用相同的数据库布局 当然 我想使用服务器和客户端上可用的 Common dll 中的相同 EDMX 文件 在客户端中 我有一个
  • T-SQL 中结果集的幂集(所有组合)

    我需要一个 t sql 代码来获取结果集的幂集 输入示例 ColumnName 1 2 3 Example Output one columns as nvarchar 1 2 3 1 2 1 3 2 3 1 2 3 输出集可能包含重复值
  • 如何创建实体集或模型而不在数据库中创建相应的表 - 实体框架

    我的 sqlserver 数据库中有一个存储过程 它返回多个结果集 我正在使用 msdn 中的以下链接从实体框架中的 SP 读取多个结果集 https msdn microsoft com en us library jj691402 v
  • 选择两列中两个日期之间的记录

    如何选择两列中两个日期之间的记录 Select From MyTable Where 2009 09 25 is between ColumnDateFrom to ColumnDateTo 我有一个日期 2009 09 25 我喜欢选择
  • 如何使用 PHP 从 MSSQL 读取图像字段

    我正在创建一个网站 需要同步从离线 MSSQL 服务器读取的在线 MySQL 数据库 除图像字段外 所有通信和从 MSSQL 读取所有字段均工作正常 我已经使用 PHP 和 Mysql 一段时间了 知道如何向 MySQL 数据库插入 检索图
  • INFORMATION_SCHEMA 与 sysobjects

    在 SQL Server 中 INFORMATION SCHEMA 和 sysobjects 之间有什么区别 其中一个是否比另一个提供更多信息 或者它们通常用于不同的用途 sysobjects 与 sys objects 相同吗 如果不是
  • 打开脚本任务时 SSIS 丢失文件引用

    我们使用自定义审核程序集 C 在脚本任务中记录 SSIS 中的多种操作 我们将在 GAC 中构建自定义程序集 用于运行时 并发布到 IDE VS2008 的公共程序集区域以供设计时文件引用 后构建完成后 自定义程序集可在运行时使用 并可在文
  • 按小时拆分日期/时间数据并将日期/时间范围展开为行

    我正在尝试使用 SQL Server 将一系列日期 时间数据扩展为多行 例如 我的数据看起来像 Date StartTime EndTime EmployeeID ShiftType 10 1 2019 8 30 00AM 4 57 00P
  • 为什么某些字符无法从 CFQUERY 正确注入到 SQL Server?

    我有一个在 Lucee 上运行的 Coldfusion 应用程序 它连接到 SQL Server 数据库 当我直接在 SQL Server 管理器中运行以下查询时 UPDATE article SET content 20m WHERE i
  • 在SQL Server中仅获取浮点数的小数部分[关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我在 SQL Server 2008
  • sql server GO 相当于 oracle

    我正在为 Oracle 编写迁移脚本 我需要更改表结构 然后用数据填充它 我想先进行结构更改 然后再进行数据更改 在 SQL Server 中我会使用GO分离批次 是否有 SQL ServerGOOracle 中的等效命令 It s and
  • 从数据库配置中的连接字符串中删除 SSIS 密码

    我有一个 SSIS 包 它使用 SQL 服务器中的 SSIS 配置表来检索 OLE DB 连接管理器的连接字符串属性 问题是我还需要相同的连接字符串来调用使用实体框架的程序集 我尝试访问连接管理器连接字符串属性 但 SSIS 总是删除密码
  • SSRS。如何在table1_Details_Group右侧创建新的行组?

    我正在使用 Microsoft Visual Studio 2013 创建报告 PROBLEM 如果我添加新的Row Group前面会自动添加table1 Details Group 问题 如何更改组的顺序或在右侧添加新组table1 De
  • SQL Server 查询结果集的大小

    SQL Server 中是否有确定结果集中 Mgmt Studio 查询中返回的数据大小 以 MEGS 为单位 您可以打开客户端统计信息 查询菜单 包括客户端统计信息 它给出执行查询时从服务器返回的字节数
  • SQL Server 转换选择一列并将其转换为字符串

    是否可以编写一条从表中选择列并将结果转换为字符串的语句 理想情况下 我希望有逗号分隔的值 例如 假设 SELECT 语句看起来像这样 SELECT column FROM table WHERE column lt 10 结果是一列包含值的
  • SQL Server 2000 中是否提供公用表表达式 (CTE)

    我最近发现了以下文章 http www tsqltutorials com with common table expressions php http www tsqltutorials com with common table exp
  • 如何在动态查询中将行值连接到列名

    我正在开发一个允许配置问题和答案的应用程序 目前最多可以有 20 个答案 但也可能更少 我的结构如下 问题 ID FormId QuestionText AnswerField 1 1 Name Answer01 2 1 Address A

随机推荐