使用C#连接到000webhost上的mysql [英] Connecting to mysql on 000webhost using C#
本文介绍了使用C#连接到000webhost上的mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是试图在控制台上读取batabase中的内容,但是我总是在conn.Open()行上遇到异常.这是所有代码:
Im simply just trying to read what there is in the batabase on to a console but i always get an exception on the conn.Open() line. Here is all the code:
SqlConnectionStringBuilder conn_string = new SqlConnectionStringBuilder();
conn_string.DataSource = "mysql14.000webhost.com"; // Server
conn_string.UserID = "a7709578_codecal";
conn_string.Password = "xxxxx";
conn_string.InitialCatalog = "a7709578_codecal"; // Database name
SqlConnection conn = new SqlConnection(conn_string.ToString());
conn.Open();
SqlCommand cmd = new SqlCommand("Select name FROM Users");
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("{1}, {0}", reader.GetString(0), reader.GetString(1));
}
reader.Close();
conn.Close();
if (Debugger.IsAttached)
{
Console.ReadLine();
}
推荐答案
000个免费的Webhost服务器不允许与服务器数据库的外部连接.
000webhost free servers does not allow external connections to the server database.
您只能通过服务器上存储的PHP脚本使用数据库.
You can only use your database from your PHP scripts stored on the server.
您可以使用PHP从数据库中获取数据,数据将返回.因此,我建议您使用C#(如api)中的php.
You can get data from database using PHP and it will return.So i advice to you using php from C# like api.
这篇关于使用C#连接到000webhost上的mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文