|
|
Question : sqlexpress connection string
|
|
Hi all...
1) connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=E:\mydb.MDF;Integrated Security=True;Connect Timeout=60;User Instance=True"
2) connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=True"
what is the difference in these .. which one is best .. and when shall i use each one of them ? what about deployment .. are they the same ?
thanks.
|
Answer : sqlexpress connection string
|
|
Unless you have a specific need to directly access the data via its file name as in
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=E:\mydb.MDF;Integrated Security=True;Connect Timeout=60;User Instance=True"
it is ALWAYS better to just refer to the database, as in
connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=mydb;Integrated Security=True"
The database could move physical location. The file could have been renamed, etc. Directly referring to the file name could possibly allow you to run a few queries on an otherwise unattached database file, but I don't see how that could be useful - you are bypassing all sorts of controls that SQL puts in place. You would have to be running at an administrative level for this to work, and this is generally not a good idea.
Performance: there will be a time penalty on initial connection while the file is attached and checked, but otherwise there should be no appreciable difference.
Security: since you can only do this as an adminitrative-level user, you've bypassed most of the security features that SQL would otherwise assist with.
Deployment: will the application absolutely KNOW where the physical data file is going to be? And where it ALWAYS will be, even years in the future? If the answer is not an emphatic "YES", then you can't really consider using the direct-filename method - any deployed applications will need updating if the file is ever moved or renamed. If the connection is based simply on db name, there is no such problem.
In summary, I cannot imagine when I would ever prefer to use the direct-filename connection method.
Hope this helps!
|
|
|
|
|