简体   繁体   中英

ADO.NET Connection String

I have a SQL Server 2008 database that uses a default schema called "Arxame". How do I specify or change the default schema from "dbo" to "Arxame" in my connection string? I'm using C# and ADO.NET.

You can't do that. You have to set the schema "Arxame" to the user you have specified on your connection string. You can do this using the SQL Server Management tool

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

The following example changes the default schema of the user Mary51 to Purchasing.

USE AdventureWorks2008R2;
ALTER USER Mary51 WITH DEFAULT_SCHEMA = Purchasing;
GO

Source: MSDN

The InitialCatalog is indeed the database name. 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.

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.

Schemas in SQL Server 2005 and up

The initial schema must be set in your connection string:

Data Source=localhost;Initial Catalog=Arxame;Integrated Security=True

Remember to use Integrated security only if you are using a Local Sql Server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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