Attach a database file, located in the data directory, on connect to a local SQL Server Express instance using SQL Server Native Client 11.0 ODBC
Connection string
This SQL Server Native Client 11.0 ODBC Driver connection string can be used for connections to SQL Server 2012, SQL Server 2008 and SQL Server 2005.
Driver={SQL Server Native Client 11.0};Server=.\SQLExpress;
AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;
Trusted_Connection=Yes;
Why is the Database parameter needed? If the named database have already been attached, SQL Server does not reattach it. It uses the attached database as the default for the connection.