0

我正在使用 System.Data.Linq.DataContext 文件来访问 mdf 数据库

我想使用项目目录中的数据库,而不是调试器在 Debug 目录中创建的数据库。

问题是当我编辑连接字符串并选择 AttachDBFilename 的路径时,VS2008 会自动将我的项目目录替换为“|DataDirectory|”

我该如何解决这个问题?

4

2 回答 2

3

编辑您的应用程序“app.config”文件
转到 connectionStrings 并将 connectionString 更改为您的数据库的路径。

在 DataContext 文件属性中,设置“应用程序设置”= True
然后通过它的名称和它选择连接。

于 2008-12-15T23:28:56.130 回答
0

你已经可以这样写了: SampledbDataContext sdc = new SampledbDataContext(Server.MapPath("~/Sampledb.mdf")); 或在 design.cs 文件中 public SampledbDataContext() : base(global::"[write cnn string Here !]", mappingSource) { OnCreated(); }

于 2011-05-12T20:40:52.893 回答