如何使用 Entity Framework Code First 自动迁移和 LocalDB 更改数据库文件位置
How to change Database file location with EntitiyFramework CodeFirst auto migration and LocalDB
我在我的 wpf 项目应用程序中使用 localdb,它首先使用 entity framework 代码。当应用程序 运行 首次将本地数据库文件创建到 'C:\Users\CurrentUserName' 路径时,默认情况下。如何将此默认路径更改为用户选择的另一个位置。
我的连接字符串
<connectionStrings>
<add name="L10CompanyContext" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=L10Company;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
就这么简单
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\path\to\Database.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
Gets or sets a string that contains the name of the primary data file.
This includes the full path name of an attachable database.
Use the SqlLocalDB utility to create an instance of Microsoft SQL
Server 2016 ExpressLocalDB. The SqlLocalDB utility (SqlLocalDB.exe) is
a simple command line tool to enable users and developers to create
and manage an instance of SQL Server ExpressLocalDB. For information
about how to use LocalDB
语法
SqlLocalDB.exe
{
[ create | c ] \<instance-name> \<instance-version> [-s ]
| [ delete | d ] \<instance-name>
| [ start | s ] \<instance-name>
| [ stop | p ] \<instance-name> [ -i ] [ -k ]
| [ share | h ] [" <user_SID> " | " <user_account> " ] " \<private-name> " " \<shared-name> "
| [ unshare | u ] " \<shared-name> "
| [ info | i ] \<instance-name>
| [ versions | v ]
| [ trace | t ] [ on | off ]
| [ help | -? ]
}
以下示例使用 SQL Server 2017 二进制文件创建名为 DEPARTMENT 的 SQL Server ExpressLocalDB 实例并启动该实例。
SqlLocalDB.exe create "DEPARTMENT" 12.0 -s
我在我的 wpf 项目应用程序中使用 localdb,它首先使用 entity framework 代码。当应用程序 运行 首次将本地数据库文件创建到 'C:\Users\CurrentUserName' 路径时,默认情况下。如何将此默认路径更改为用户选择的另一个位置。
我的连接字符串
<connectionStrings>
<add name="L10CompanyContext" connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=L10Company;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
就这么简单
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\path\to\Database.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
Gets or sets a string that contains the name of the primary data file. This includes the full path name of an attachable database.
Use the SqlLocalDB utility to create an instance of Microsoft SQL Server 2016 ExpressLocalDB. The SqlLocalDB utility (SqlLocalDB.exe) is a simple command line tool to enable users and developers to create and manage an instance of SQL Server ExpressLocalDB. For information about how to use LocalDB
语法
SqlLocalDB.exe
{
[ create | c ] \<instance-name> \<instance-version> [-s ]
| [ delete | d ] \<instance-name>
| [ start | s ] \<instance-name>
| [ stop | p ] \<instance-name> [ -i ] [ -k ]
| [ share | h ] [" <user_SID> " | " <user_account> " ] " \<private-name> " " \<shared-name> "
| [ unshare | u ] " \<shared-name> "
| [ info | i ] \<instance-name>
| [ versions | v ]
| [ trace | t ] [ on | off ]
| [ help | -? ]
}
以下示例使用 SQL Server 2017 二进制文件创建名为 DEPARTMENT 的 SQL Server ExpressLocalDB 实例并启动该实例。
SqlLocalDB.exe create "DEPARTMENT" 12.0 -s