aws天蓝网站的mysql连接问题

时间:2017-12-14 03:49:50

标签: mysql azure amazon-web-services

我似乎找不到我的问题的答案。

我用.net创建了一个快速的小网站,并将其发布在azure上。 当我测试它时,我可以查询我的aws mysql db就好了但是在发布后我得到了。

System.InvalidOperationException: Connection must be valid and open. at 
MySql.Data.MySqlClient.Interceptors.ExceptionInterceptor.Throw(Exception 
exception) at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex) at 
MySql.Data.MySqlClient.MySqlCommand.Throw(Exception ex) at 
MySql.Data.MySqlClient.MySqlCommand.CheckState() at 
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) 
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() at 
TaskiiLink._Default.Page_Load(Object sender, EventArgs e) in 
C:\............\Default.aspx.cs:line 39

第39行:MySqlDataReader reader = command.ExecuteReader();

我的连接字符串是:

 <add name="dbconn" connectionString="user id=NAME;Password=PASS;persistsecurityinfo=true;server=AWSENDPOINT;Port=3306;database=DB;" providerName="MySql.Data.MySqlClient"/>

页面加载代码

 if(Request["type"] == "1")
   {
     string sql = "checkDB";
     conn.Open();
     using (MySqlCommand command = new MySqlCommand(sql))
      {         
       command.Connection = conn;
       try
        {
          MySqlDataReader reader = command.ExecuteReader();
          if (!reader.Read())
             {
               Response.Write("false");
             } else
             {
               Response.Write("true");
             }

2 个答案:

答案 0 :(得分:0)

您需要传递连接对象。

with open(fname) as f:

答案 1 :(得分:0)

自己想出来,

AWS安全组仅允许我的本地主机ip作为入站。

在azure portal的属性设置中找到了我的网络应用程序出站IP。

如果有人遇到同样的问题,请提供有用的链接。

AWS问题

https://forums.aws.amazon.com/thread.jspa?threadID=176030

azure info

https://social.msdn.microsoft.com/forums/azure/en-US/fd53afb7-14b8-41ca-bfcb-305bdeea413e/maintenance-notice-upcoming-changes-to-increase-capacity-for-outbound-network-calls

我在添加ip解决方案时遇到的问题。

https://forums.aws.amazon.com/thread.jspa?threadID=158994