Visual Studio项目中的SQL连接字符串问题 [英] SQL Connection string issue in Visual Studio projects

查看:117
本文介绍了Visual Studio项目中的SQL连接字符串问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

当我构建解决方案项目(7个项目)时,每个项目在其app.config文件中都有一个SQL连接字符串.可以很好地连接到我的SQL DB Server.

When I built my solution projects (7 projects), each project had a SQL connection string in its app.config file. which worked fine connecting to my SQL DB Server.

现在,当我尝试在另一台计算机上运行该解决方案并尝试将其连接到另一个数据库时,我将收到一个SQL错误,无法找到该SQL DB的实例.即使该数据库实例的名称与该计算机的名称/主机相同,不一样. (在我的服务器上 连接字符串是:该实例的MYSERVER \ DBSERVER,在计算机上,我正在尝试将其安装在MYPC \ DBSERVER上)

Now when I tried running the solution on another computer and tried connecting it to another DB I would get a SQL error not able to find instance of the SQL DB.Even if the DB instance name is the same the computer name/host is not the same. (on my server connection string is : MYSERVER\DBSERVER for the instance and on the computer I am trying to install it on MYPC\DBSERVER)

我尝试使用main.exe修改配置文件,但该配置文件仅适用于主项目,不适用于仍在尝试查找数据库服务器的其他项目.

I tried modifying the config file with the main.exe but that only worked for the main project not the other ones that are still trying to look for my DB server.

我该如何解决?

谢谢

推荐答案

您是否已将连接字符串添加到app.config中,还是在使用数据设计器时为您创建的?此处的底线是您已设计该应用程序以使用硬连线的连接字符串,因此可以动态地切换数据库 除非您添加或修改代码,否则这样做会成问题.
Did you add the connection string to the app.config or was it created for you when using the Data Designer? The bottom line here is that you have designed the app to use a hard-wired connection string, so switching databases dynamically is going to be problematic unless you add or modify the code to do so.


这篇关于Visual Studio项目中的SQL连接字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆