ODBC模式驗證方法權限查詢
ODBC備份模式下有兩種驗證方法:可信驗證和MS SQL驗證。 以下過程可以幫助確定:
- 用於在ODBC備份模式下對MS SQL 伺服器資料庫備份進行驗證的登錄憑據具有正確的權限。
- 為了獲得假脫機資料庫的大小,以確保臨時資料夾所在的驅動程序有足夠的空間來容納備份期間數據庫的假脫機。
可信驗證
若要驗證可信驗證的登錄憑據是否具有訪問和後台處理MS SQL Server資料庫以進行備份作業的正確權限,建議使用以下命令:
osql -E -Q "DECLARE @dbname char(64) SET @dbname = 'xxx' BACKUP DATABASE @dbname TO DISK = '%temporary_path%\%database_name.txt' WITH SKIP"
請注意:
- %temporary_path%是MS SQL Server備份集上臨時文件夾的位置(例如E:\ temp)。
- 'xxx' 是用於備份的資料庫名稱。
示例方案:使用具有足夠權限的Windows用戶帳戶的可信驗證
- 使用特定帳戶(例如管理員)登錄Windows。
- 打開命令提示符。
- 應用下列osql指令。
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>osql -E -Q "DECLARE @dbname char(64) SET @dbname = 'adventureworks2016' BACKUP DATABASE @dbname TO DISK ='E:\temp\adventureworks2016.bak' WITH SKIP"
Processed 26240 pages for database 'adventureworks2016', file
'AdventureWorks2016_Data' on file 5.
Processed 2 pages for database 'adventureworks2016', file
'AdventureWorks2016_Log' on file 5.
BACKUP DATABASE successfully processed 26242 pages in 14.397 seconds (14.239 MB/sec).
C:\Users\Administrator>
上述示例中
- @dbname = 'adventureworks2016' - ‘adventureworks2016’ 是用於備份的資料庫名稱。
- @dbname TO DISK ='E:\temp\adventureworks2016.bak' - ‘E:\temp’ 是MS SQL Server備份集上臨時文件夾的位置。
- 如果'adventureworks2016’資料庫成功保存到臨時資料夾(E:\Temp),驗證該賬戶具有正確的權限。 為了檢查資料庫是否成功建立,並獲取假脫機數據庫的大小,以確保臨時驅動器有足夠的空間來容納備份期間數據庫文件的假脫機,運行下列指令。
C:\Users\Administrator>dir E:\Temp
Volume in drive E has no label.
Volume Serial Number is 16F4-EB51
Directory of E:\Temp
09/07/2020 11:18 AM DIR .
09/07/2020 11:18 AM DIR ..
09/07/2020 12:06 PM 1,075,228,160 adventureworks2016.bak
09/07/2020 11:18 AM 215,046,656 inventory.bak
09/04/2020 06:42 PM 4,024,832 master.bak
3 File(s) 1,429,402,815 bytes
2 Dir(s) 21,348,990,976 bytes free
C:\Users\Administrator>
示例方案: 使用權限不正確的帳戶進行的可信驗證
當使用不具有訪問MS SQL資料庫的正確權限的Windows登錄帳戶時,將顯示以下錯誤消息。
C:\Users\backup1>osql -E -Q "DECLARE @dbname char(64) SET @dbname = 'adventureworks2016' BACKUP DATABASE @dbname TO DISK ='E:\temp\adventureworks2016.bak' WITH SKIP"
[ODBC Driver 13 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [2].
Login failed for user 'W2K16-MSSQL2K16\backup1'.
[ODBC Driver 13 for SQL Server]A network-related or instance-specific error
has occurred while establishing a connection to SQL Server. Server is not
found or not accessible. Check if instance name is correct and if SQL Server
is configured to allow remote connections. For more information see SQL Server
Books Online.
C:\Users\backup1>
上述示例中,用戶‘backup1’ 沒有正確的權限。因此,無法建立MS SQL 伺服器連接。
MS SQL 驗證
若要驗證MS SQL驗證的登錄憑據是否具有訪問和假脫機MS SQL 伺服器資料庫以進行備份作業的正確權限,建議應用下列指令:
osql -U USERNAME -P PASSWORD -Q "DECLARE @dbname char(64) SET @dbname = 'xxx' BACKUP DATABASE @dbname TO DISK = '%temporary_path%\%database_name.txt' WITH SKIP"
請注意:
- %temporary_path%是MS SQL Server備份集上臨時文件夾的位置(例如E:\ temp)。
- 'xxx' 是用於備份的資料庫名稱。
- USERNAME是MS SQL伺服器賬戶的用戶名稱。
- PASSWORD是MS SQL伺服器賬戶的用戶密碼。
示例方案: 使用具有足夠權限的帳戶進行MS SQL 驗證
- 使用特定帳戶(例如管理員)登錄Windows。
- 打開命令提示符。
- 應用下列osql指令。
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>osql -U sa -P abc123$% -Q "DECLARE @dbname char(64) SET @dbname = 'master' BACKUP DATABASE @dbname TO DISK = 'E:\temp\master.bak' WITH SKIP"
Processed 480 pages for database 'master', file 'master' on
file 2.
Processed 3 pages for database 'master', file 'mastlog' on
file 2.
BACKUP DATABASE successfully processed 483 pages in 0.785 seconds (4.802 MB/sec).
C:\Users\Administrator>
上述示例中,
- osql -U sa - ‘sa’是MS SQL伺服器賬戶預設用戶名稱。
- -P abc123$% - ‘abc123$%’是MS SQL伺服器賬戶密碼。
- @dbname = 'master' - ‘master’是用於備份的資料庫名稱。
- @dbname TO DISK = 'E:\temp\master.bak' - ‘E:\temp’ 是MS SQL Server備份集上臨時文件夾的位置。
- 如果'adventureworks2016’資料庫成功保存到臨時資料夾(E:\Temp),驗證該賬戶具有正確的權限。 為了檢查資料庫是否成功建立,並獲取假脫機數據庫的大小,以確保臨時驅動器有足夠的空間來容納備份期間數據庫文件的假脫機,運行下列指令。
C:\Users\Administrator>dir E:\Temp
Volume in drive E has no label.
Volume Serial Number is 16F4-EB51
Directory of E:\Temp
09/07/2020 11:18 AM DIR .
09/07/2020 11:18 AM DIR ..
09/07/2020 12:06 PM 1,075,228,160 adventureworks2016.bak
09/07/2020 11:18 AM 215,046,656 inventory.bak
09/04/2020 06:42 PM 4,024,832 master.bak
3 File(s) 1,429,402,815 bytes
2 Dir(s) 21,348,990,976 bytes free
C:\Users\Administrator>
示例方案: 使用權限不正確的帳戶進行的MS SQL驗證。
當使用不具有訪問MS SQL資料庫的正確權限的Windows登錄帳戶時,將顯示以下錯誤消息。
C:\Users\Administrator>osql -U mssql1 -P abc123$% -Q "DECLARE @dbname char(64) SET @dbname = 'master' BACKUP DATABASE @dbname TO DISK = 'E:\temp\master.bak' WITH SKIP"
[ODBC Driver 13 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [2].
Login failed for user 'mssql1'.
[ODBC Driver 13 for SQL Server]A network-related or instance-specific error
has occurred while establishing a connection to SQL Server. Server is not
found or not accessible. Check if instance name is correct and if SQL Server
is configured to allow remote connections. For more information see SQL Server
Books Online.
C:\Users\Administrator>
上述示例中,用戶‘mssql1’沒有正確的權限。因此,無法建立MS SQL 伺服器連接。