Alterar a propriedade dos meus Bancos de Dados no SQL Server 2016?

2

Eu instalei o MSSQL Server 2016 no Windows 10 Home e criei alguns bancos de dados. Em seguida, atualizei para o Windows 10 Pro e agora, como estou fazendo login no SQL como um usuário diferente (o usuário antigo era local, o novo usuário é o domínio), ele não me permitirá acessar meus bancos de dados - não posso atribuir usuários para acessá-los, não consigo abri-los, não posso excluí-los.

Eu tentei:

  • Criando um novo usuário do SQL e atribuindo direitos
  • Efetuando login no Windows como usuário local (que foi removido e não pode ser recriado no computador local)
  • Atribuindo direitos ao usuário administrador do domínio (no Management Studio)

Eu não sei as credenciais sa .

Como posso obter acesso aos meus bancos de dados?

    
por Ben 22.07.2016 / 07:17

2 respostas

2

Aqui está outro método que pode ajudá-lo a obter acesso à instância do SQL Server na sua máquina Windows 10 ; Eu não usei este, mas pode funcionar também.

Reset Forgotten SA Password

  1. Click Start, point to Run and type cmd, press Enter key.

enter image description here

  1. The command prompt will appear. Run the command:

    Osql –S john –E

    Replace john with your actual computer name.

  2. Then type this command to change your forgotten SA password.

    EXEC sp_password NULL, ’123456’, ’sa’

    Replace 123456 with the password you want.

  3. Type Go to make the change take effect.

  4. Now you are able to log into the SA account with your new password!

You can also use this method to change SQL Server passwords of other user accounts. If you're still unable to reset the SA password or SA account is locked out or disabled, please check out this article: 2 Methods to Unlock SQL Server SA Account When It's Locked Out.

source

    
por 22.07.2016 / 08:09
2

Dê uma chance a este script e veja se ele adiciona a conta de usuário que executa um acesso à instância do SQL Server em sua máquina com Windows 10. Isso precisará ser salvo em um arquivo CMD ou BAT, renomeando um documento de texto e, em seguida, ele precisará ser executado; é um script em lote.

Eu obtive isso de Microsoft (eu postarei a fonte se eu a encontrar) há alguns anos e a usei para uma instalação SQL Express para conceder acesso sysadmin a uma conta de administrador local em um servidor eu acho que eu salvei uma vez eu confirmei que funcionou no caso de eu precisar novamente.

@echo off
:: 
:: ****************************************************************************
:: 
::    Copyright (c) Microsoft Corporation. All rights reserved.
::    This code is licensed under the Microsoft Public License.
::    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
::    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
::    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
::    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
:: 
:: ****************************************************************************
:: 
:: CMD script to add a user to the SQL Server sysadmin role
:: 
:: Input:  %1 specifies the instance name to be modified. Defaults to SQLEXPRESS.
::         %2 specifies the principal identity to be added (in the form "<domain>\<user>").
::            If omitted, the script will request elevation and add the current user (pre-elevation) to the sysadmin role.
::            If provided explicitly, the script is assumed to be running elevated already.
:: 
:: Method: 1) restart the SQL service with the '-m' option, which allows a single connection from a box admin
::            (the box admin is temporarily added to the sysadmin role with this start option)
::         2) connect to the SQL instance and add the user to the sysadmin role
::         3) restart the SQL service for normal connections
:: 
:: Output: Messages indicating success/failure.
::         Note that if elevation is done by this script, a new command process window is created: the output of this
::         window is not directly accessible to the caller.
:: 
::

setlocal
set sqlresult=N/A
if .%1 == . (set /P sqlinstance=Enter SQL instance name, or default to SQLEXPRESS: ) else (set sqlinstance=%1)
if .%sqlinstance% == . (set sqlinstance=SQLEXPRESS)
if /I %sqlinstance% == MSSQLSERVER (set sqlservice=MSSQLSERVER) else (set sqlservice=MSSQL$%sqlinstance%)
if .%2 == . (set sqllogin="%USERDOMAIN%\%USERNAME%") else (set sqllogin=%2)

:: 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

:: elevate if <domain/user> was defaulted
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
:: determine if the SQL service is running
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

:: if required, stop the SQL service
if .%srvstate% == .1 goto startm
set srvstarted=1
@echo Stop the '%sqlservice%' service ...
net stop %sqlservice%
if errorlevel 1 goto stoperror

:startm
:: start the SQL service with the '-m' option (single admin connection) and wait until its STATE is '4' (STARTED)
:: also use trace flags as follows:
::     3659 - log all errors to errorlog
::     4010 - enable shared memory only (lpc:)
::     4022 - do not start autoprocs
@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

:: add the specified user to the sysadmin role
:: access tempdb to avoid a misleading shutdown error
@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

:: stop the SQL service
@echo Stop the '%sqlservice%' service ...
net stop %sqlservice%
if errorlevel 1 goto stoperror
if .%srvstarted% == .0 goto exit

:: start the SQL service for normal connections
net start %sqlservice%
if errorlevel 1 goto starterror
goto exit

:: handle unexpected errors
: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
pause
    
por 22.07.2016 / 08:00

Tags