我第一次写 access数据库的东西我都是把 连数据库的 字符串写在 web.config 里面的
这样
<appSettings>
<add key="conn" values="字符串">
</appSettings>但我现在用不了虚拟路径了,我用虚拟路径,系统自动把目录指到 c:\windows\system32里了,郁闷
我现在只能把绝对路径写上,但这样把项目放到别的机器上肯定不好用啊,得改路径。怎么样才能让我的 连接字符串 用虚拟路径正确?
这样
<appSettings>
<add key="conn" values="字符串">
</appSettings>但我现在用不了虚拟路径了,我用虚拟路径,系统自动把目录指到 c:\windows\system32里了,郁闷
我现在只能把绝对路径写上,但这样把项目放到别的机器上肯定不好用啊,得改路径。怎么样才能让我的 连接字符串 用虚拟路径正确?
2、在web.config里写数据库存放的相对路径,然后把它和上面的路径组合起来就是数据库的物理路径了
2、在web.config里写数据库存放的相对路径,然后把它和上面的路径组合起来就是数据库的物理路径了
<configuration>
<!-- 请修改以下的数据库绝对路径。-->
<appSettings>
<add key="strConn" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=xxx.mdb"/>
</appSettings><system.web>
<compilation defaultLanguage="vb" debug="true" />
<customErrors mode="RemoteOnly" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20"
/>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</configuration>
<appSettings>
<!-- 总部起始目录 -->
<add key="WebUI_DataPath" value="WebData99" />
</appSettings>
Global.asax.cs:
protected void Session_Start(Object sender, EventArgs e)
{
string svrroot = Server.MapPath("/");
if ( svrroot.EndsWith( "\\" ) ) svrroot = svrroot.Remove( svrroot.Length-1,1 );
// 服务器路径 形如:c:\inetpub\wwwroot
Session["ServerPath"]= svrroot ;
string curdir = Server.MapPath(".").Substring( svrroot.Length+1 ) + "\\";
//获取当前路径如:/yueyang/SchOnline 中第一级目录,如:yueyang, 如果为空则表示总部
string SubSch= curdir.Substring(0, curdir.IndexOf( '\\' ) );
// 当前分校应用程序路径,形如:/yueyang表示岳阳,/表示总部
Session["AppPath"] = "/" + SubSch;
// 当前数据文件路径,形如:c:\inetpub\wwwroot\WebData99
Session["DataPath"]= svrroot.Substring(0, svrroot.LastIndexOf('\\') ) +"\\"
+ ConfigurationSettings.AppSettings[ SubSch + "_DataPath"];
}
但我输出路径的时候 是指向到 c:\window\system32 文件夹下而不是我网站根目录下
private static string connString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + System.Web.HttpContext.Current.Server.MapPath("data/book.mdb");
public static string ConnString
{
get
{
return connString;
}
}