Windows应用程序忽略app.config并使用某些东西连接到本地数据库
该应用程序位于虚拟环境中,当我远程登录并运行该应用程序时,它会连接到远程数据库。但是,当我使用服务帐户远程登录并双击相同的 .exe 时,它会尝试连接到本地主机数据库并忽略 app.config。代码是一样的,只是我使用的登录名不同。我使用的登录名是本地管理员组的一部分。有什么想法吗?
The application sits on a virtual environment and when I remote in and run the application, it connects to the remote database. However, when I remote in with a service account and double click the same .exe, it tries to connect to the local host database and ignores the app.config. The code is the same, only the login name I use is different. The login I use is part of the local admin group. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有指出您的问题中是否属于这种情况,但我的第一个怀疑是您将连接字符串存储在设置中,但连接字符串已被标记为用户特定的设置。
You haven't indicated whether or not this is the case in your question, but my first suspicion is that you are storing the connection strings in settings, but the connection string has been marked as a user-specific setting.
在代码逻辑中,它会将配置(设置)中的 SQL 服务器设置(以小写形式输入)与 SQL 服务器列表(全部以大写形式)进行比较。由于找不到任何匹配项,数据源为空白 [datasource=;],因此导致代码看起来是本地的。我的修复方法是使用 String.Compare 并忽略大小写,这会创建匹配项,并且我能够连接到远程 SQL 服务器。
In the logic of the code it was doing a comparison of the SQL server setting in the config (Settings), which was entered in lower case, against the list of SQL servers (all in upper case). Since it couldn't find any match, the datasource was blank [datasource=;],hence causing the code to look local. My fix was to use String.Compare and ignore the case, which created the match and I was able to connect to the remote SQL server.