SqlServer 認證之包含資料庫

來源:互聯網
上載者:User

標籤:

包含資料庫(Contained Database): 作用是這個資料庫的建立的使用者不需要再指定登陸名就可以串連訪問。

優點:資料庫在異地恢愎時,不需要再建立登陸名。即遷移的時候不再需要在新執行個體上添加登陸名。(PS:Alawayson 沒有同步登陸名和作業。這個可以解決登陸名的問題)

缺點:只能訪問自身資料庫,並不能訪問同一執行個體上的其他資料庫。(PS:博主未能訪問成功,不是肯定不能訪問)

使用步驟:

 執行個體支援:

     

EXEC sys.sp_configure N‘contained database authentication‘, N‘1‘GORECONFIGURE WITH OVERRIDEGO

 

 

   建立或修改資料庫的包含類型為部份。

   

Create Database DBName Containment=partial
Alter DataBase DBName set Containment=partial

當修改資料庫時,還需要將映射到 SQL Server 登入名的資料庫使用者轉換為具有密碼的包含資料庫使用者。

使用系統預存程序:

sp_migrate_user_to_contained [ @username = ] N‘user‘ ,       [ @rename = ] { N‘copy_login_name‘ | N‘keep_name‘ } ,       [ @disablelogin = ] { N‘disable_login‘ | N‘do_not_disable_login‘ }  

參考代碼:

DECLARE @username sysname ;  DECLARE user_cursor CURSOR      FOR           SELECT dp.name           FROM sys.database_principals AS dp          JOIN sys.server_principals AS sp           ON dp.sid = sp.sid          WHERE dp.authentication_type = 1 AND sp.is_disabled = 0;  OPEN user_cursor  FETCH NEXT FROM user_cursor INTO @username      WHILE @@FETCH_STATUS = 0      BEGIN          EXECUTE sp_migrate_user_to_contained           @username = @username,          @rename = N‘keep_name‘,          @disablelogin = N‘disable_login‘;      FETCH NEXT FROM user_cursor INTO @username      END  CLOSE user_cursor ;  DEALLOCATE user_cursor ;  

參考網址

https://msdn.microsoft.com/zh-cn/library/ff929275.aspx

 串連時指定資料庫名。即串連串中,需要指定initial catalog 或Database

 

  

SqlServer 認證之包含資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.