我已经用 C# 构建了我的程序,问题是我为我的数据库使用“Microsoft SQL Server 数据库文件(SqlClient)”,我想让它可移植,因为如果我把所有项目(sln)交给我的朋友运行它,数据库路径当然是错误的..
所以我的项目 C# 目录中有 database.mdf,所以我的问题是,你知道一种方法吗?
我尝试了一些模式的连接字符串,
Data Source=.\SQLEXPRESS;AttachDbFilename="D:\blabla\blablaa\blablaaa\blablaaaa\WindowsFormsApplication2\WindowsFormsApplication2\WindowsFormsApplication2\WindowsFormsApplication2\Database1.mdf";Integrated Security=True;User Instance=True
所以我这样做了
Data Source=.\SQLEXPRESS;AttachDbFilename="..\WindowsFormsApplication2\WindowsFormsApplication2\WindowsFormsApplication2\WindowsFormsApplication2\Database1.mdf";Integrated Security=True;User Instance=True
或者
Data Source=.\SQLEXPRESS;AttachDbFilename="..\Database1.mdf";Integrated Security=True;User Instance=True
有什么建议么。