【问题标题】:web.config connection string to different database serverweb.config 连接字符串到不同的数据库服务器
【发布时间】:2014-01-06 17:11:37
【问题描述】:
我的 web.config 中有两个 conn 字符串
其中第二个连接到外部数据库 - 数据库与当前网站位于不同的服务器上。
- 有可能吗?
- 如何编写连接字符串?
我现在有这个:
<add name="newConn" connectionString="server=www.somedomain.com;database=dbname;user id=dbuser;password=dbpass" providerName="MySql.Data.MySqlClient" />
但我收到错误消息:
拒绝用户 'dbuser'@'currentdnsserver.com' 的访问(使用密码:YES)
谢谢
【问题讨论】:
标签:
asp.net
web-config
database-connection
connection-string
database-server
【解决方案1】:
您有 2 个问题:
答案:
1. Absolutely.
2. You will need to write a connection string that use TCP/IP as the transport.
要对此进行调试,您应该尝试使用您在 conn 字符串中使用的凭据通过 SQL Server Mgmt Studio 进行连接。
我假设您使用的是 SQL Server,这是使用 SQL Server 身份验证到启用 TCP/IP 的 DBMS 的典型连接字符串。
<add name="conn2" connectionString="Database=myDB;Server=serverNameOrIpAddress;uid=id;pwd=pwd;" providerName="System.Data.SqlClient"/>
【解决方案2】:
我想建立的连接是在不同的托管服务器之间(一个在 Windows 上,另一个在 Linux 上)。
我的托管服务提供商告诉我无法从 Windows .NET 网站连接到 Linux MySQL db。不知道为什么,但不可能。
可能在他们所说的同一主机上。
感谢您尝试帮助@T McKeown
【解决方案3】:
是的,您可以连接到远程服务器,这经常被使用。
您应该在连接字符串中编辑的主要内容是:数据源。
例子:
Data Source=192.166.0.2;initial catalog=books;integrated security=False;user id=admin;password=!password1
数据源:您要连接的计算机的 IP 或 URL
初始目录:您要使用的数据库的名称
使用时要使用的数据库用户的用户名和密码
数据库是必需的。