[英]How to change oledb connection string dynamically, so it can be used for each target machine?
i am developing a win form project in c#. 我正在用c#开发一个win表单项目。 I am facing a problem, I am using a
.mdb
db file, and a connection string to use it eg @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\mohan\\Documents\\VisualStudio2010\\Projects\\AotoInformation\\AotoInformation\\common\\appDb.mdb;Persist Security Info=True"
我面临一个问题,我正在使用
.mdb
db文件,以及使用它的连接字符串,例如@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\mohan\\Documents\\VisualStudio2010\\Projects\\AotoInformation\\AotoInformation\\common\\appDb.mdb;Persist Security Info=True"
Now I am making an .exe
file of my project, but when someone install this .exe
to his system, this connection string can't work. 现在,我正在制作项目的
.exe
文件,但是当有人将此.exe
安装到他的系统中时,此连接字符串将无法工作。
How can I get a connection string that can be used on every target machine, no matter where user install the app? 无论用户在哪里安装应用程序,如何获取可在每台目标计算机上使用的连接字符串?
set the connection string in your code instead of config file. 在代码而不是配置文件中设置连接字符串。 you can find app root path using AppDomain.CurrentDomain.BaseDirectory.
您可以使用AppDomain.CurrentDomain.BaseDirectory查找应用程序的根路径。
连接字符串只是一个字符串..因此,最初,您可以将其保留为..Data Source=@mdbFilePath..
之类的东西..Data Source=@mdbFilePath..
当请求连接字符串时,请将@mdbFilePath
替换为您的mdb文件路径...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.