PDO连接字符串主机

时间:2017-05-15 13:48:27

标签: c# php mysql pdo

我试图将我的C#输入放在我的mysql中。 我希望我工作的同学也可以访问数据库,这就是为什么我不使用localhost。但我一直得到这个

错误:

  

ERROR SQLSTATE [HY000] [2002]连接尝试失败,因为   连接方在一段时间后没有正确响应,或者   连接的连接失败,因为连接的主机没有   回应。

或者这不是将数据库放到网上的正确方法吗?

php连接字符串。 (我不知道主持人是否正确?)

$bdd= new PDO ("mysql:host=phpmyadmin.webserver.roc-teraa.nl;port=3306;dbname=wikiparks","$username", "$password");

C#

private void btnToevoegen_Click(object sender, EventArgs e)
        {
            try
            {
                NameValueCollection ParkInfo = new NameValueCollection();
                ParkInfo.Add("ParkNaam", txbPretpark.Text);
                ParkInfo.Add("ParkLocatie", txbLocatiePretpark.Text);
                ParkInfo.Add("ParkOpeningsDagen", txbOpeningsDagen.Text);
                ParkInfo.Add("ParkOpeningsTijden", txbOpeningsTijden.Text);
                ParkInfo.Add("ParkPrijzen", txbPrijzenPretpark.Text);
                ParkInfo.Add("ParkLeeftijden", txbLeeftijdPretpark.Text);
                ParkInfo.Add("ParkTags", txbTags.Text);
                ParkInfo.Add("ParkBeschrijving", rtbBeschrijving.Text);

                byte[] InsertPark = client.UploadValues("http://localhost:8080/WikiParks/index.php", "POST", ParkInfo);
                client.Headers.Add("Content-Type", "binary/octet-stream");
            }
            catch (Exception)
            {
                MessageBox.Show("Pretpak succesvol toegevoegd aan de Database");
            }


        }

1 个答案:

答案 0 :(得分:0)

PDO in dotNET
[enter link description here][1]
  [1]: https://www.nuget.org/packages/SDO_dotNET/

    The SDO_dotNET Class Library is a high level wrapper around the ODBC, OLEDB, SQLServer and SQLite.

Example:
using SqlDB;

/******************************************************************
Sql Server
*******************************************************************/

string server      = @"INSTANCE\SQLEXPRESS";
string database = "DEMODB";
string username = "sa";
string password = "";

string connectionString = @"Data Source=" + server + ";Initial Catalog=" + database + "; Trusted_Connection=True;User ID=" + username + ";Password=" + password + "";
SDO db_conn = new SDO(connectionString);

Console.WriteLine("isConnected: " + db_conn.isConnected());
if (db_conn == null || !db_conn.isConnected())
{
    Console.WriteLine("Connessione non valida.");
    return;
}

string sql = "SELECT ID, Message FROM Logs ORDER BY IDLic;";
DataTable dtLogs = db_conn.SelectTable(sql);

if (dtLogs == null || dtLogs.Rows.Count == 0)
    return;

// Loop with the foreach keyword.
foreach (DataRow dr in dtLogs.Rows)
{
    Console.WriteLine("Message: " + dr["Message"].ToString().Trim());
}



/******************************************************************
SQLite
*******************************************************************/

string database = @"C:\Users\Utente\mydb.sqlite";

string connectionString = @"Data Source=" + database + "; Version=3; New=True; Compress=True;"; // local
SDO db_conn = new SDO(connectionString);

Console.WriteLine("isConnected: " + db_conn.isConnected());
if (db_conn == null || !db_conn.isConnected())
{
    Console.WriteLine("Connessione non valida.");
    return;
}

string sql = "SELECT firstname, surname FROM users ORDER BY firstname;";
DataTable dtLogs = db_conn.SelectTable(sql);

if (dtLogs == null || dtLogs.Rows.Count == 0)
    return;

// Loop with the foreach keyword.
foreach (DataRow dr in dtLogs.Rows)
{
    Console.WriteLine("Name: " + dr["firstname"].ToString().Trim() + " " + dr["surname"].ToString().Trim());
}