How is this done? Well, to start with, ADO.NET adds a couple of new keywords to the ConnectionString. The ConnectionString is the set of parameters passed to ADO that tells it how to find and access the target data source, as well as identify the user. It also contains settings for a number of options, including how long to wait for the connection to complete and, in this case, the name of the user database to attach. This keyword (Attach-DBFilename) points to a user .MDF file which contains the preconfigured and prepopulated SQL Server database. When the ADO Open method sees this keyword, it tells SQL Server to attach this file and install it as a new databaseat least the first time. Each subsequent time the application runs, SQL Server determines if this is the same file it attached the first time and simply opens the existing database. When you use the default AutoClose option, SQL Server automatically disconnects from the data file when the last user closes his connection. This permits an uninstall application to delete the file and not disturb SQL Server.
Another ConnectionString option is used to create an entirely separate instance of the server. By specifying “User Instance=True” along with the “AttachDBFilename=
”, ADO (and SQL Server) make a copy of the master, model, tempdb, and user databases and write them to the user area on disk. This disk region is not visible to other (nonadministrator) users. The connection open method then fires up this unique instance and provides unrestricted access to the user database. This entirely new approach is hoped to protect both SQL Server’s databases and the user database from other users, as well as provide a way to permit the user to log in as system administrator without worrying that they might cause problems that would impact other users or other databases.