连接到OpenShift服务

时间:2016-04-26 03:48:05

标签: c# mysql openshift

我刚刚进入OpenShift,请耐心等待。我在我的域上设置了一个MySQL数据库,并且能够从phpMyAdmin页面添加和删除项目。我现在想在我的机器上创建一个应用程序,并且只在我的机器上连接到数据库,并且能够具有读/写访问权限。我已经为这个用户设置了一个权限集,并准备好一个C#表单进行编码。我已经执行了以下操作:

rhc port-forward --app <my application name>

之后,我收到了以下内容:

W:\>rhc port-forward --app <my application name>
DL is deprecated, please use Fiddle
Checking available ports ... done
Forwarding ports ...
Only one usage of each socket address (protocol/network address/port) is
normally permitted. - bind(2) while forwarding port 8080. Trying local port 8081
To connect to a service running on OpenShift, use the Local address
Service Local               OpenShift
httpd   127.0.0.1:8080  =>  127.3.223.1:8080
httpd   127.0.0.1:8081  =>  127.3.223.3:8080
mysql   127.0.0.1:3306  =>  127.3.223.2:3306
Press CTRL-C to terminate port forwarding

所以当我回到C#时,我有以下代码行:

conn = new SqlConnection("user id="+tbUser.Text+";password="+tbPass.Text+";server=127.0.0.1:3306;database=<my application name>");
conn.Open();

但是我在.Open()函数上遇到错误,说它无法找到服务器或数据库。我不知道发生了什么。

编辑:我想我不妨添加错误消息,如果有用的话:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

1 个答案:

答案 0 :(得分:2)

您应该使用应用网址而不是IP地址,您列出的每个地址都是loopback interface,并且不代表您的应用网址。

尝试使用http://yourappdomain.rhcloud.com:3306