简体   繁体   English

ADO.NET连接字符串

[英]ADO.NET Connection String

I have a SQL Server 2008 database that uses a default schema called "Arxame". 我有一个SQL Server 2008数据库,该数据库使用名为“ Arxame”的默认架构。 How do I specify or change the default schema from "dbo" to "Arxame" in my connection string? 如何在连接字符串中将默认架构从“ dbo”指定或更改为“ Arxame”? I'm using C# and ADO.NET. 我正在使用C#和ADO.NET。

You can't do that. 你不能那样做。 You have to set the schema "Arxame" to the user you have specified on your connection string. 您必须将架构“ Arxame”设置为在连接字符串上指定的用户。 You can do this using the SQL Server Management tool 您可以使用SQL Server管理工具执行此操作

If you need to change the default schema for an existing user you can do it like this 如果您需要更改现有用户的默认架构,则可以这样做

B. Changing the default schema of a user B.更改用户的默认架构

The following example changes the default schema of the user Mary51 to Purchasing. 下面的示例将用户Mary51的默认架构更改为“购买”。

USE AdventureWorks2008R2; 使用AdventureWorks2008R2;
ALTER USER Mary51 WITH DEFAULT_SCHEMA = Purchasing; ALTER USER Mary51 WITH DEFAULT_SCHEMA =购买;
GO

Source: MSDN 资料来源: MSDN

The InitialCatalog is indeed the database name. InitialCatalog确实是数据库名称。 The schema that is used would depend on the user you specify, since schemas typically map to database users. 因为架构通常映射到数据库用户,所以使用的架构将取决于您指定的用户。 Whatever user owns the Arxame schema is the one you should specify in the connection string. 拥有Arxame模式的任何用户都应该在连接字符串中指定。

I do not believe you can do this within a connection string, nor should you be able to. 我不认为您可以在连接字符串中执行此操作,也不应该这样做。 You use schemas, in much the same was as a namespace in C#, to further resolve securable objects within a database when there may be name collisions. 使用模式(与C#中的命名空间几乎相同)可以在可能发生名称冲突时进一步解析数据库中的安全对象。

Schemas in SQL Server 2005 and up SQL Server 2005及更高版本中的架构

The initial schema must be set in your connection string: 必须在您的连接字符串中设置初始模式:

Data Source=localhost;Initial Catalog=Arxame;Integrated Security=True 数据源=本地主机;初始目录= Arxame;集成安全性=真

Remember to use Integrated security only if you are using a Local Sql Server. 请记住仅在使用本地Sql Server时才使用集成安全性。

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

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