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”中被拒绝 的相关文章

  • 如果不存在则插入数据(来自 2 个表),否则更新

    再会 我有3张桌子 tbl仓库产品 ProductID ProductName ProductCode Quantity tbl分公司产品 ProductID ProductCode ProductCode Quantity Locatio
  • 将存储过程的结果加上额外的列插入表中

    如何在其中插入更多列dbFileListOnly表以及 EXEC 查询 INSERT INTO admindb dbfilelistonly path col1 col2 path EXEC RESTORE FILELISTONLY FRO
  • 增量SQL查询

    我的应用程序有一组固定的 SQL 查询 这些查询以轮询模式运行 每 10 秒一次 由于数据库的大小 gt 100 GB 和设计 超级规范化 我遇到了性能问题 每当数据库上发生更改查询结果的 CRUD 事件时 是否可以对给定查询进行增量更改
  • 如何更新 SQL Server 中 ntext 列中的 XML 字符串?

    有一个包含 2 列的 SQL 表 ID int 和值 ntext 值行中包含各种 xml 字符串 ID Value 1
  • 当没有文件可供下载时,如何避免 SSIS FTP 任务失败?

    我正在使用 SQL Server 2005 并在 SSIS 中创建 ftp 任务 有时会有文件需要通过 ftp 传输 有时则不会 如果没有文件 我不希望任务或包失败 我已将从 ftp 任务到下一个任务的箭头更改为 完成 以便包运行 我已将允
  • SQL 查询在多用户环境中返回错误值

    一段时间以来 我们在我们的一个客户站点上发现了奇怪的数据完整性问题 经过大量调查后 我们现在已将其隔离为数据库调用 如果两个用户同时调用同一个存储过程 有时一个用户会得到另一个用户的结果 我们设置了一个测试来验证这一点 并且我们有一个循环
  • T-SQL 按最旧日期和唯一类别选择行

    我正在使用 Microsoft SQL 我有一个表 其中包含按两个不同类别存储的信息和一个日期 例如 ID Cat1 Cat2 Date Time Data 1 1 A 11 00 456 2 1 B 11 01 789 3 1 A 11
  • 扁平化/反规范化 SQL 查找表的最佳方法?

    我有很多这样的表 Lookup HealthCheckupRisks ID Name 1 Anemia 2 Anorexic 3 Bulemic 4 Depression 122 Syphilis PatientRisksOnCheckup
  • 显示包含特定表的所有数据库名称

    我的 SQL Server 中有很多数据库 我必须只搜索包含特定表名的数据库名称Heartbitmaster 我有很多数据库 例如Gotgold DVD等 我只想从包含此表的查询中查找数据库名称Heartbitmaster 我搜索我尝试查询
  • 存储过程总是返回0

    我试图从存储过程获取返回值 但它总是返回 0 c code cmd new SqlCommand cmd CommandType CommandType StoredProcedure cmd CommandText AbsentEntry
  • 无论如何要解密加密的sql server存储过程吗?

    我有几个 ms sql server 2000 存储过程 很久以前就被前雇员加密了 一切都很好 直到我们需要稍微改变一下 有什么方法可以检索源代码吗 或者重写是唯一的选择 多谢 或者免费 谷歌是你的朋友 http searchsqlserv
  • 如何从 SQL Server 中的 SELECT 进行更新?

    In SQL服务器 可以将行插入到带有INSERT SELECT陈述 INSERT INTO Table col1 col2 col3 SELECT col1 col2 col3 FROM other table WHERE sql coo
  • 如何在 SQL Server 中创建文件格式

    我正在尝试在 SQL Server 2017 中试验外部文件 但在第一步中遇到了困难 数据是管道分隔的 我试图遵循文档中的语法 这需要一个FILE FORMAT 以下是 Microsoft 的语法 CREATE EXTERNAL TABLE
  • SQL Server lat;lng varchar 分割过程用作 Lat 和 Lng 以提高搜索速度

    有人可以帮助我使用存储过程或函数来传递我的存储varchar表中的 lat lng 到各个字段作为浮点数作为 Lat 和 Lng 以在半径搜索中使用 lanlng in Table 33 0000 15 222222 Thanks 你只是想
  • 每行中非空列的计数

    我有一个包含 4 列的表 在第 5 列中我想存储前 4 列中有多少个非空列的计数 例如 其中 X 是任意值 Column1 Column2 Column3 Column4 Count X X NULL X 3 NULL NULL X X 2
  • SQL Server 中的嵌套事务

    sql server 允许嵌套事务吗 如果是的话那么交易的优先级是什么 来自 SQL Server 上的 MSDN 文档 嵌套交易 http msdn microsoft com en us library ms189336 SQL 90
  • 在 SQL Server 2005 IMAGE 列中存储 20 Meg 文件的最有效方法

    我们将文档存储在 SQL Server 2005 数据库表中 列格式为 Image 每次我尝试存储大于 1 Meg 的 PDF 文件时 它都会以某种方式损坏 NET 中是否有任何特别有效的方法来序列化大文件 10megs 并将其存储到数据库
  • sql server 2008 对 exec 语句的限制

    我只需要仔细检查 t sql 中的 EXEC 命令是否有字符限制 如果我有一个带有 varchar max 的变量并使用 EXEC 执行命令 你认为这样可以吗 thanks 应该没问题 根据这篇 MSDN 文章 http msdn micr
  • 如何搜索表中的所有列?

    如何在 SQL Server 中搜索表的所有列 SELECT FROM yourtable WHERE val IN field1 field2 field3 field4 如果您正在寻找精确的全场比赛 如果你正在寻找子字符串匹配 你将不得
  • Sql Server 的夏令时

    我们正在使用一个以 C Unix 格式存储日期的旧应用程序 C 时间基本上是自 1970 年 1 月 1 日以来的秒数 日期以整数形式存储在 SQL Server 数据库中 我正在为使用这些日期的报告编写视图 到目前为止 我正在使用以下命令

随机推荐