views:

661

answers:

2

Every SQL Server connection string I ever see looks something like this:

Data Source=MyLocalSqlServerInstance;Initial Catalog=My Nifty Database;
    Integrated Security=SSPI;

Do I need the Initial Catalog setting? (Apparently not, since the app I'm working on appears to work without it.)

Well, then, what's it for?

+4  A: 

This is the initial database of the data source when you connect.

Edited for clarity:

If you have multiple databases in your SQL Server instance and you don't want to use the default database, you need some way to specify which one you are going to use.

Andy West
The first part is correct. The second part is not correct. When you create the account it is assigned a default database which will be used if initial catalog is not specified. This generally defaults to master (for some unknown reason).
GrayWizardx
When I say "by default" I simply mean when you are not qualifying the database in your object names. In any case, I have clarified my answer.
Andy West
+2  A: 

If the user that is the connection string has access to more then one database you have to specify the database you want the connection string to connect to. If your user has only one database available then you are correct that it doesn't matter. But it is good practice to put this in your connection string.

Avitus
Not quite true. The login may not have permissions on the default database. So, you need to change the database context on connection
gbn