2010-02-15 41 views
4

我想使用ASP.NET應用程序服務,但將其配置爲使用其他模式。我使用的是this URL中列出的aspnet_regsql.exe工具,默認情況下,該工具創建表並使用dbo架構存儲特效。將ASP.NET應用程序服務配置爲使用「dbo」以外的模式

所以我想我可以從現有的應用程序對象中生成一個數據庫腳本,然後用[示例]查找並替換[dbo],然後刪除原始的應用程序服務對象並執行編輯的腳本以獲得結果我想了。只會採取一個微笑。

但在閱讀this斯科特顧博客帖子中有評論部分的人已經嘗試過這種方法,並發現它倒下了。斯科特通過請求關於這個問題的電子郵件回覆,我認爲這是對問題的承認,但我沒有看到任何解決方案。

所以我在數據建模階段,我真的不想在賽道上出現很多麻煩。有沒有人知道這是否已經解決,或者如果在'dbo'模式問題的查找和替換方法中繼續存在任何障礙?

UPDATE:

,所以我沒有連得「很遠走下賽場」上倒下了。顯然,配置數據庫非常容易,因此所有對象都可以使用新模式正確引用對方,但是它的顯示所有支持代碼都已硬連接「dbo」引用......而不是使用連接用戶帳戶的默認模式。

只需嘗試使用VS Studio> Project | ASP.NET配置工具足以打破它。修改web配置指向新的數據庫與調整後的模式,然後進入配置工具的安全選項卡,我得到一個錯誤「無法找到存儲過程'dbo.aspnet_CheckSchemaVersion'」。所以會出現「DBO」已被烤:(

更新2:

所以我同義詞已經添加爲接受的答案概述和它的作品,但我確實有。在爲了得到它的滾動進入4個記錄到數據庫採取了全程30秒)

在此之前我得到了以下錯誤:

The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'

所以我不得不從aspnet_Applications表複製一個應用程序行。然後從aspnet_SchemaVersions表中選擇3行。我從默認的dbo模式安裝中獲得了這些信息。

這是aspnet_Applications記錄(蒙面 'XXXX' 的唯一性 - 你必須讓自己的密鑰):

/ /xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx NULL 

這些是aspnet_SchemaVersions記錄:

common 1 True 

membership 1 True 

role manager 1 True 

它現在所有的作品。如果我將來遇到任何問題,我會更新這篇文章。

回答

2

在這種情況下,答案很可能在於使用與別名類似的Sql Server SYNONYMS。這篇文章How and why should I use SQL Server 2005 synonyms?有一個介紹。

你基本上要:

CREATE SYNONYM 
    [dbo].[aspnet_CheckSchemaVersion] 
FOR 
    [yourschema].[aspnet_CheckSchemaVersion] 

對於每個受影響的對象。這可能是費時因此該腳本將可能會有一定的好處:

SELECT 'CREATE SYNONYM [dbo].[' + p.Name + '] FOR [' + s.Name + '].[' + p.Name + ']' FROM sys.Procedures p INNER JOIN 
sys.Schemas s on p.schema_id = s.schema_id 

你需要複製粘貼上述腳本的輸出到一個新的腳本窗口和執行。所以這個想法是,你正在使用一個腳本來生成其他腳本命令。

如果您然後執行上述腳本的輸出,它將爲db中的所有過程創建同義詞。

所以注意:

  1. 假定您在只應用服務特效分貝。如果您有自己的自定義特效,那麼您將不得不添加一個WHERE條件來過濾僅適用於以'aspnet_'開頭的應用服務對象,即

    WHERE p.name LIKE'aspnet_%'。

  2. 此過程假定您已經完成查找並替換以設置新的模式。即從原始數據庫生成數據庫腳本,在dbo模式引用上完成查找和替換操作,然後刪除/刪除原始dbo對象,然後運行修改後的腳本以獲取所需的[schema]。[object]設置,然後然後最後使用上面的腳本。

  3. 使用SYNONYM的性能成本將取決於應用程序。

聽起來像很多麻煩,但整個過程可能需要3-4分鐘。

1

腳本的輸出上面會如下所以你可以複製粘貼和運行查找並替換它爲「yourschema」讓你SYNONYM構建腳本:

CREATE SYNONYM [dbo].[aspnet_UnRegisterSchemaVersion] FOR [yourschema].[aspnet_UnRegisterSchemaVersion] 
CREATE SYNONYM [dbo].[aspnet_RegisterSchemaVersion] FOR [yourschema].[aspnet_RegisterSchemaVersion] 
CREATE SYNONYM [dbo].[aspnet_CheckSchemaVersion] FOR [yourschema].[aspnet_CheckSchemaVersion] 
CREATE SYNONYM [dbo].[aspnet_Membership_CreateUser] FOR [yourschema].[aspnet_Membership_CreateUser] 
CREATE SYNONYM [dbo].[aspnet_Profile_SetProperties] FOR [yourschema].[aspnet_Profile_SetProperties] 
CREATE SYNONYM [dbo].[aspnet_Roles_CreateRole] FOR [yourschema].[aspnet_Roles_CreateRole] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationAllUsers_ResetPageSettings] FOR [yourschema].[aspnet_PersonalizationAllUsers_ResetPageSettings] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationAllUsers_SetPageSettings] FOR [yourschema].[aspnet_PersonalizationAllUsers_SetPageSettings] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationAllUsers_GetPageSettings] FOR [yourschema].[aspnet_PersonalizationAllUsers_GetPageSettings] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationAdministration_GetCountOfState] FOR [yourschema].[aspnet_PersonalizationAdministration_GetCountOfState] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationAdministration_ResetSharedState] FOR [yourschema].[aspnet_PersonalizationAdministration_ResetSharedState] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationAdministration_ResetUserState] FOR [yourschema].[aspnet_PersonalizationAdministration_ResetUserState] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationPerUser_GetPageSettings] FOR [yourschema].[aspnet_PersonalizationPerUser_GetPageSettings] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationPerUser_ResetPageSettings] FOR [yourschema].[aspnet_PersonalizationPerUser_ResetPageSettings] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationPerUser_SetPageSettings] FOR [yourschema].[aspnet_PersonalizationPerUser_SetPageSettings] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationAdministration_DeleteAllState] FOR [yourschema].[aspnet_PersonalizationAdministration_DeleteAllState] 
CREATE SYNONYM [dbo].[aspnet_PersonalizationAdministration_FindState] FOR [yourschema].[aspnet_PersonalizationAdministration_FindState] 
CREATE SYNONYM [dbo].[aspnet_Profile_DeleteProfiles] FOR [yourschema].[aspnet_Profile_DeleteProfiles] 
CREATE SYNONYM [dbo].[aspnet_Setup_RestorePermissions] FOR [yourschema].[aspnet_Setup_RestorePermissions] 
CREATE SYNONYM [dbo].[aspnet_Setup_RemoveAllRoleMembers] FOR [yourschema].[aspnet_Setup_RemoveAllRoleMembers] 
CREATE SYNONYM [dbo].[aspnet_Membership_FindUsersByName] FOR [yourschema].[aspnet_Membership_FindUsersByName] 
CREATE SYNONYM [dbo].[aspnet_Membership_FindUsersByEmail] FOR [yourschema].[aspnet_Membership_FindUsersByEmail] 
CREATE SYNONYM [dbo].[aspnet_AnyDataInTables] FOR [yourschema].[aspnet_AnyDataInTables] 
CREATE SYNONYM [dbo].[aspnet_Applications_CreateApplication] FOR [yourschema].[aspnet_Applications_CreateApplication] 
CREATE SYNONYM [dbo].[aspnet_Users_DeleteUser] FOR [yourschema].[aspnet_Users_DeleteUser] 
CREATE SYNONYM [dbo].[aspnet_Users_CreateUser] FOR [yourschema].[aspnet_Users_CreateUser] 
CREATE SYNONYM [dbo].[aspnet_Membership_GetUserByName] FOR [yourschema].[aspnet_Membership_GetUserByName] 
CREATE SYNONYM [dbo].[aspnet_Membership_GetUserByUserId] FOR [yourschema].[aspnet_Membership_GetUserByUserId] 
CREATE SYNONYM [dbo].[aspnet_Membership_GetUserByEmail] FOR [yourschema].[aspnet_Membership_GetUserByEmail] 
CREATE SYNONYM [dbo].[aspnet_Membership_GetPasswordWithFormat] FOR [yourschema].[aspnet_Membership_GetPasswordWithFormat] 
CREATE SYNONYM [dbo].[aspnet_Membership_UpdateUserInfo] FOR [yourschema].[aspnet_Membership_UpdateUserInfo] 
CREATE SYNONYM [dbo].[aspnet_Membership_GetPassword] FOR [yourschema].[aspnet_Membership_GetPassword] 
CREATE SYNONYM [dbo].[aspnet_Membership_SetPassword] FOR [yourschema].[aspnet_Membership_SetPassword] 
CREATE SYNONYM [dbo].[aspnet_Membership_ResetPassword] FOR [yourschema].[aspnet_Membership_ResetPassword] 
CREATE SYNONYM [dbo].[aspnet_Membership_UnlockUser] FOR [yourschema].[aspnet_Membership_UnlockUser] 
CREATE SYNONYM [dbo].[aspnet_Membership_UpdateUser] FOR [yourschema].[aspnet_Membership_UpdateUser] 
CREATE SYNONYM [dbo].[aspnet_Membership_ChangePasswordQuestionAndAnswer] FOR [yourschema].[aspnet_Membership_ChangePasswordQuestionAndAnswer] 
CREATE SYNONYM [dbo].[aspnet_Membership_GetNumberOfUsersOnline] FOR [yourschema].[aspnet_Membership_GetNumberOfUsersOnline] 
CREATE SYNONYM [dbo].[aspnet_Profile_DeleteInactiveProfiles] FOR [yourschema].[aspnet_Profile_DeleteInactiveProfiles] 
CREATE SYNONYM [dbo].[aspnet_Profile_GetNumberOfInactiveProfiles] FOR [yourschema].[aspnet_Profile_GetNumberOfInactiveProfiles] 
CREATE SYNONYM [dbo].[aspnet_Profile_GetProfiles] FOR [yourschema].[aspnet_Profile_GetProfiles] 
CREATE SYNONYM [dbo].[aspnet_UsersInRoles_IsUserInRole] FOR [yourschema].[aspnet_UsersInRoles_IsUserInRole] 
CREATE SYNONYM [dbo].[aspnet_UsersInRoles_GetRolesForUser] FOR [yourschema].[aspnet_UsersInRoles_GetRolesForUser] 
CREATE SYNONYM [dbo].[aspnet_Roles_DeleteRole] FOR [yourschema].[aspnet_Roles_DeleteRole] 
CREATE SYNONYM [dbo].[aspnet_Roles_RoleExists] FOR [yourschema].[aspnet_Roles_RoleExists] 
CREATE SYNONYM [dbo].[aspnet_Roles_GetAllRoles] FOR [yourschema].[aspnet_Roles_GetAllRoles] 
CREATE SYNONYM [dbo].[aspnet_UsersInRoles_AddUsersToRoles] FOR [yourschema].[aspnet_UsersInRoles_AddUsersToRoles] 
CREATE SYNONYM [dbo].[aspnet_UsersInRoles_RemoveUsersFromRoles] FOR [yourschema].[aspnet_UsersInRoles_RemoveUsersFromRoles] 
CREATE SYNONYM [dbo].[aspnet_UsersInRoles_GetUsersInRoles] FOR [yourschema].[aspnet_UsersInRoles_GetUsersInRoles] 
CREATE SYNONYM [dbo].[aspnet_UsersInRoles_FindUsersInRole] FOR [yourschema].[aspnet_UsersInRoles_FindUsersInRole] 
CREATE SYNONYM [dbo].[aspnet_Profile_GetProperties] FOR [yourschema].[aspnet_Profile_GetProperties] 
CREATE SYNONYM [dbo].[aspnet_Paths_CreatePath] FOR [yourschema].[aspnet_Paths_CreatePath] 
CREATE SYNONYM [dbo].[aspnet_WebEvent_LogEvent] FOR [yourschema].[aspnet_WebEvent_LogEvent] 
CREATE SYNONYM [dbo].[aspnet_Personalization_GetApplicationId] FOR [yourschema].[aspnet_Personalization_GetApplicationId] 
CREATE SYNONYM [dbo].[aspnet_Membership_GetAllUsers] FOR [yourschema].[aspnet_Membership_GetAllUsers] 
相關問題