我正在使用C#,我正在尝试连接到由00webhost托管的
MySQL数据库.
我在线路上遇到错误.打开():
我已经检查过,一切似乎都很好.
string MyConString = "SERVER=MysqL7.000webhost.com;" + "DATABASE=a455555_test;" + "UID=a455555_me;" + "PASSWORD=something;"; MysqLConnection connection = new MysqLConnection(MyConString); MysqLCommand command = connection.CreateCommand(); MysqLDataReader Reader; command.CommandText = "INSERT Test SET lat=" + OSGconv.deciLat + ",long=" + OSGconv.deciLon; connection.open(); Reader = command.ExecuteReader(); connection.Close();
这个连接字符串有什么问题?
解决方法
尝试创建连接字符串这样:
MysqLConnectionStringBuilder conn_string = new MysqLConnectionStringBuilder(); conn_string.Server = "MysqL7.000webhost.com"; conn_string.UserID = "a455555_test"; conn_string.Password = "a455555_me"; conn_string.Database = "xxxxxxxx"; using (MysqLConnection conn = new MysqLConnection(conn_string.ToString())) using (MysqLCommand cmd = conn.CreateCommand()) { //watch out for this sql injection vulnerability below cmd.CommandText = string.Format("INSERT Test (lat,long) VALUES ({0},{1})",OSGconv.deciLat,OSGconv.deciLon); conn.open(); cmd.ExecuteNonQuery(); }
原文地址:https://www.jb51.cc/csharp/96576.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。