Visual Studio 2013 上的连接字符串与 SQL 服务器 2014

Connection String on Visual Studio 2013 with SQL Server 2014

这是我 Visual Studio 上的连接字符串,我的数据库文件名为 IOOP_Database

Data Source=IDEA-PC\SQLEXPRESS;Initial Catalog=IOOP_Database;Integrated Security=True

问题是当我运行这个系统在另一台笔记本电脑上时,会因为连接字符串出现错误。有什么方法可以将我的连接字符串声明为 Date Source=IOOP_Database.mdf?我还将我的 mdf 文件移动到我的 Visual Studio 项目的调试文件夹中,因此项目文件和 sql 数据库文件实际上在一起。

您可以在连接字符串中使用 AttachDbFilename 属性。它有一些限制,建议仅在开发环境而不是生产环境中使用。

AttachDBFilename is unique to SQL Express, it spins up a user instance of SQL Express attached to a specific DB Filename for single user mode. Database is simply the name of the database to use, it has no additional connotation. For any production server, you would most likely not be using AttachDBFilename. It is strictly useful for development and experimentation in single-user mode. from MSDN forum

您可能还会发现这些有用: