60

With SQL Server 2005 and 2008 is it possible to set the default schema from the connection string? It'd be a lot easier if we didn't have to manually set the schema with SQL code.

5 Answers 5

46

No, this is done at the database User level, not in the connection string.

For reference, here are all of the properties which can be set in a connection string: https://www.connectionstrings.com/all-sql-server-connection-string-keywords/

44

You set the default schema based on the user who is logging in via the connection, not the connection itself.

ALTER USER Mary51 WITH DEFAULT_SCHEMA = Purchasing;

Reference:

4
  • 1
    That would really suck for us though :/
    – Earlz
    Commented Jul 19, 2010 at 15:53
  • LMAO..I posted exactly the same thing :-)
    – SQLMenace
    Commented Jul 19, 2010 at 15:53
  • 4
    You mean you both came up with mary5 as a random name? Noway!
    – disklosr
    Commented Jun 27, 2018 at 19:29
  • A very good idea. But is it possible to do this in AWS Redshift?
    – saadi
    Commented Feb 17, 2020 at 11:33
13

change the default schema associated with that login

example

ALTER USER Mary51 WITH DEFAULT_SCHEMA = Purchasing;

More detail here: http://msdn.microsoft.com/en-us/library/ms176060.aspx

2

If when you say "Schema," you mean "Owner" (i.e. dbo), then I believe the selected answer is correct.

However, if you mean "Database" instead, which in some vendor's lingo means the same thing as "Schema," then I have provided some more info below.

In the link that TimS provided:

Scroll down to the row with these two properties:

Initial Catalog -or- Database

Here's an example connection string with a DEFAULT DATABASE:

Server=myServerName\myInstanceName,1433;Database=DEFAULT_DATABASE;User Id=myUsername;Password=myPassword;

See link below for more examples:

0

I have had this problem too.
I removed Integrated Security=sspi; from my connection string and then it worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.