Skip to main content
.NET Framework 4.5.2+

MSSqlConnectionProvider.GetConnectionStringWithAttachForLocalDB(String, String, String) Method

Returns the connection string to SQL Server 2012 Express LocalDB for the specified server, database and database file location.

Namespace: DevExpress.Xpo.DB

Assembly: DevExpress.Xpo.v24.1.dll

NuGet Package: DevExpress.Xpo

Declaration

public static string GetConnectionStringWithAttachForLocalDB(
    string server,
    string database,
    string attachDbFilename
)

Parameters

Name Type Description
server String

A string that is the server name.

database String

A string that is the database name.

attachDbFilename String

A string that is the path to the MDB file.

Returns

Type Description
String

A string that is the connection string to SQL Server 2012 Express LocalDB for the specified server, database and database file location.

Remarks

An example of creating the connection string to the local server instance using the absolute path to MDB file:

MSSqlConnectionProvider.GetConnectionStringWithAttachForLocalDB(
    "(localdb)\\v11.0", "DatabaseName", "D:\\Data\\DatabaseName.mdf");

An example of creating the connection string to the local server instance using the path to MDB file located in the DataDirectory folder:

MSSqlConnectionProvider.GetConnectionStringWithAttachForLocalDB(
    "(localdb)\\v11.0", "DatabaseName", "|DataDirectory|\\DatabaseName.mdf");

To connect to the local server instance when the database files are located in the %USERPROFILE% folder, use the MSSqlConnectionProvider.GetConnectionString method instead of GetConnectionStringWithAttachForLocalDB:

MSSqlConnectionProvider.GetConnectionString("(localdb)\\v11.0", "DatabaseName");

To connect to a custom LocalDB instance, pass the server parameter in the following notation.

Refer to the SQL Server 2012 Express LocalDB topic in MSDN to learn more about naming LocalDB instances. You do not need to use the SqlLocalDB.exe console tool provided by Microsoft to handle instances, as XPO includes the MSSqlLocalDBApi helper class that wraps the API described in the SQL Server Express LocalDB Instance API Reference document.

See Also