SQLNCLI11 OLEDBAttach a database file, located in the data directory, on connect to a local SQL Server Express instance

Provider=SQLNCLI11;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.

Connecting

This connection string (Attach a database file, located in the data directory, on connect to a local SQL Server Express instance using SQLNCLI11 OLEDB) can be used for connections to SQL Server 2012.

Articlesread all »

Not the right connection string for you?

Start over in the connection string reference index.

You can also get help in the Q&A forums where you can ask your own question.

The kb articles contains how-tos and instructions and you can search for anything if you're not sure were to look.