我在项目中建立了与本地数据库的连接。这是我的代码:
class Connection
{
public SqlConnection GetConnection()
{
string mycon = @"data source=(LocalDB)\v11.0;" + @"attachdbfilename=G:\distributor_Portal\distributor_Portal\App_Data\DistributorPortal.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True";
SqlConnection con = new SqlConnection(mycon);
return con;
}
public static String GetConnectionString()
{
return "";
}
}
我的问题是我不想提供完整的地址,例如G:\distributor_Portal\distributor_Portal\App_Data\DistributorPortal.mdf
。我想提供参考路径。
答案 0 :(得分:0)
将附件文件部分更改为:
@"attachdbfilename=|DataDirectory|\DistributorPortal.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True";