简体   繁体   English

ASP.NET Web.Config文件指定DataSource ConnectionString

[英]ASP.NET Web.Config File Specifying A DataSource ConnectionString

I'm trying to use an 'SQL Express' (or is it SQL Compact?) .MDF file as the datasource on a simple website using a Chart control. 我正在尝试使用'SQL Express'(或者它是SQL Compact?)。MDF文件作为使用Chart控件的简单网站上的数据源。

Locally, it works great; 在当地,它很棒; but only if the 'AttachDbFilename' has the full path. 但仅当'AttachDbFilename'具有完整路径时。 Am I messing something up, or does it really need to be full path? 我搞砸了什么,还是真的需要走完全路? If so - how do I accomplish this without using something like Server.MapPath()? 如果是这样 - 如何在不使用Server.MapPath()之类的情况下实现此目的?

<add name="LocalSqlServer"
     connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"

By default, the |DataDirectory| 默认情况下,| DataDirectory | variable will be expanded as follow: 变量将扩展如下:

  • For applications placed in a directory on the user machine, this will be the app's (.exe) folder. 对于放置在用户计算机上的目录中的应用程序,这将是应用程序的(.exe)文件夹。
  • For apps running under ClickOnce, this will be a special data folder created by ClickOnce 对于在ClickOnce下运行的应用程序,这将是ClickOnce创建的特殊数据文件夹
  • For Web apps, this will be the App_Data folder 对于Web应用程序,这将是App_Data文件夹

You can programmatically set DataDirectory by calling AppDomain.CurrentDomain.SetData("DataDirectory", newpath) 您可以通过调用AppDomain.CurrentDomain.SetData("DataDirectory", newpath)以编程方式设置DataDirectory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM