大佬教程收集整理的这篇文章主要介绍了c#连接字符串和连接app.config,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
OleDbConnection con = new OledbConnection("Provider=Microsoft.ACE.oLEDB.12.0;Data source=" + System.AppDomain.CurrentDomain.baseDirectory() + "Data\rctts.mdb;jet OLEDB:Database password=mypassword;")
我的问题是,如何将连接字符串放在app.config文件中?一般来说,我使用:
<connectionStrings> <add name="Test" connectionString="Data source=.;Initial Catalog=OmidPayamak;Integrated Security=True" providerName="System.Data.sqlClient" /> </connectionStrings>
我面临的问题是,在我的连接字符串中,我正在进行一些连接,并且还使用System.AppDomain.CurrentDomain.baseDirectory()来设置数据源…
我如何在app.config中进行相同的连接?有可能这样做吗?
connectionString="Data source=|DataDirectory|\rctts.mdb;Initial Catalog=OmidPayamak;Integrated Security=True"
然后尝试将DataDirectory的值设置如下:
var currentDomain = AppDomain.CurrentDomain; var basePath = currentDomain.baseDirectory; currentDomain.SetData("DataDirectory",basePath+"\Data");
在您的应用程序的相应启动文件中.
@H_944_2@ @H_944_2@以上是大佬教程为你收集整理的c#连接字符串和连接app.config全部内容,希望文章能够帮你解决c#连接字符串和连接app.config所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。