views:

38

answers:

4

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.

A: 

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.

David Conde
Initial Catalog is the database name, not the schema name, right?
icemanind
-1 = This is incorrect. The initial catalog is the database within the instance that you would like to connect to.
Dave White
sorry about that!!!! my bad!
David Conde
A: 

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.

Chris Tybur
So Chris, Can you provide me an with an example please?
icemanind
In SQL Server 2005 and up, Schemas do not map to database users and should not be treated as such. http://msdn.microsoft.com/en-us/library/ms190387.aspx
Dave White
Maybe 'map' was the wrong word. I meant associated, in the sense that you specify which schema a database user is going to use.
Chris Tybur
A: 

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

Claudio Redi
I get it. Thanks for the clearification
icemanind
A: 

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

Dave White