如何形成一个正确的MySQL连接string?
我正在使用C#,我试图连接到00webhost托pipe的MySQL数据库。
我得到错误的线connection.Open()
:
这个参数没有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();
这个连接string有什么问题?
尝试创build连接string这种方式:
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(); }
这里是一个例子:
MySqlConnection con = new MySqlConnection( "Server=ServerName;Database=DataBaseName;UID=username;Password=password"); MySqlCommand cmd = new MySqlCommand( " INSERT Into Test (lat, long) VALUES ('"+OSGconv.deciLat+"','"+ OSGconv.deciLon+"')", con); con.Open(); cmd.ExecuteNonQuery(); con.Close();
string MyConString = "Data Source='mysql7.000webhost.com';" + "Port=3306;" + "Database='a455555_test';" + "UID='a455555_me';" + "PWD='something';";
- 启用tcp \ ip远程连接到sql server express已经安装了数据库的代码或脚本(查询)
- 致命错误:调用未定义函数mysqli_result()
- 持久的数据库连接 – 是或否?
- SQL Express连接string:相对于应用程序位置的mdf文件位置
- 为什么总是closures数据库连接
- 什么是以编程方式testingSQL Server连接的最佳方法?
- SQL Server连接string中“Initial Catalog”的含义是什么?
- Sql Server Profiler中的“exec sp_reset_connection”是什么意思?
- 如果我不closuresPython SQLite中的数据库连接,该怎么办?