what is the difference between initial catalog and databasename while writing connectionstring

Posted by Akiii under C# on 2/18/2011 | Points: 10 | Views : 22512 | Status : [Member] | Replies : 6
SqlConnection conn = new SqlConnection("Data Source=<machine-name>;initial catalog=<database-name> ; User ID=<***>;Password=<***>");

SqlConnection conn = new SqlConnection("Data Source=<machine-name>;database=<database-name> ; User ID=<***>;Password=<***>");

Both of these lines are okay and are running fine but what is the difference between initial catalog and databasename while writing connectionstring ??
what does initial catalog means ??

Please enlightened me on this thing. I am new to dotnet.

Thank you




Responses

Posted by: Madhu.b.rokkam on: 2/18/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
When ever you want to connect to a Database on a server we need to specify the initial catelog.
Where as if you want to attach a database file (.mdb file) we need to specify the database name.

Thanks and Regards
Madhu

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 2/18/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Initial Catalog and Database are simply two ways of selecting the database associated with the connection.

"Inital Catalog=main;"
-or-
"Database=main;"



Thanks
Karthik
www.f5Debug.net

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 2/18/2011 [Member] Bronze | Points: 25

Up
0
Down
Thank you very much Madhu Sir and Karthik Sir for the explanation.
I am looking forward for more help in the future....



Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 2/18/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Sure Akiii feel free to post your queries and we will be happy to help you.

Thanks and Regards
Madhu

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tripati.patro on: 2/18/2011 [Member] Starter | Points: 25

Up
0
Down
But still the answer is not clear.
If we want to give a sql server database name we can give database =""

B.Tripati Patro
Oracle Certified Associate

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 2/18/2011 [Member] Bronze | Points: 25

Up
0
Down
If the user that is the connection string has access to more then one database name then you have to specify the database you want the connection string to connect to. If your user has only one database available then it doesn't matter. In-case of multiple databases you give the database name, in-case of only one database available, you give "initial catalog".

please correct me if i am wrong!

Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response