简体   繁体   English

SQL Server-数据未写入正确的架构

[英]SQL Server - data is not written in to the correct schema

In my database I have two schema - default .dbo and another called .ptx Almost all tables in the two schema are identical. 在我的数据库中,我有两个模式-默认.dbo和另一个称为.ptx。两个模式中的几乎所有表都是相同的。 We need two schema to handle data separately for two different products. 我们需要两个模式来分别处理两个不同产品的数据。 How I switch between these two schema is by changing the SQL server login user from application level. 我如何在这两种模式之间切换是通过从应用程序级别更改SQL Server登录用户。 ie, we have two SQL users ANF_DEFAULT and ANF_PTX. 即,我们有两个SQL用户ANF_DEFAULT和ANF_PTX。 If the product is default the user is ANF_DEFAULT and if the product is PTX, I switch the user to ANF_PTX and create the SqlConnection accordingly. 如果该产品为默认用户,则用户为ANF_DEFAULT;如果该产品为PTX,则将用户切换为ANF_PTX,并相应地创建SqlConnection。

Everything has been working good so far, the two schema were populated correctly. 到目前为止,一切工作正常,两个模式已正确填充。 But suddenly after we move in to a new production environment, the PTX product data goes in to the .dbo schema instead of the .ptx schema. 但是在进入新的生产环境后,PTX产品数据突然进入了.dbo模式而不是.ptx模式。 This is still working fine in my local environment but the issue is visible in production. 在我的本地环境中,这仍然可以正常工作,但是该问题在生产中很明显。 The only visible change is that I use SQL Server 2008, where as the production runs SQL Server 2012, but I think this is hardly the issue. 唯一可见的变化是我使用SQL Server 2008,在生产环境中运行SQL Server 2012,但我认为这几乎不是问题。 I also checked the properties of the ANF_PTX user: 我还检查了ANF_PTX用户的属性:

USE [ANX_GLF]
GO

/****** Object:  User [ANF_PTX]    Script Date: 8/27/2014 5:29:04 AM ******/
CREATE USER [ANF_PTX] FOR LOGIN [ANF_PTX] WITH DEFAULT_SCHEMA=[PTX]
GO

Please help me figure out the issue here. 请帮助我在这里找出问题。

I figured out the reason for this issue. 我找出了这个问题的原因。 Apparently, in the new deployment, the _CMS user looked fine, with its default schema being pointed to .cms. 显然,在新部署中,_CMS用户看起来不错,其默认架构指向.cms。 However, the problem was with the login FMSI_APP_CMS in the SQL Server. 但是,问题出在SQL Server中的登录FMSI_APP_CMS。 In this login, the FMSI_APP_CMS user was assigned to the super admin role. 在此登录名中,将FMSI_APP_CMS用户分配给超级管理员角色。 When the user is a super admin, its default schema is ignored and it always points to the .dbo schema. 当用户是超级管理员时,其默认架构将被忽略,并且始终指向.dbo架构。 When the superadmin role was removed from the login, the schema switch was working fine again. 从登录名中删除超级管理员角色后,架构开关再次正常运行。 More information about this can be found in the following: http://msdn.microsoft.com/en-us/library/ms176060.aspx 可以在下面找到关于此的更多信息: http : //msdn.microsoft.com/zh-cn/library/ms176060.aspx

Here it says: "he value of DEFAULT_SCHEMA is ignored if the user is a member of the sysadmin fixed server role. All members of the sysadmin fixed server role have a default schema of dbo." 它说:“如果用户是sysadmin固定服务器角色的成员,则DEFAULT_SCHEMA的值将被忽略。sysadmin固定服务器角色的所有成员均具有默认架构dbo。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM