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.2.dll
Declaration
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:
To connect to a custom LocalDB instance, pass the server parameter in the following notation.
- “localdb\InstanceName” - if the Update 4.0.2 for Microsoft .NET Framework 4 patch is installed.
- “np:\.\pipe\LOCALDB#F365A78E\tsql\query” - if the former patch is not installed.
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.