Guest User

Untitled

a guest
Oct 7th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. C:\Program Files\Unity\Hub\Editor\2018.1.9f2\Editor\Data\Mono\lib\mono\2.0
  2.  
  3. Copy Npgsql.dll and System.Data.dll from this directory and put it into Assets/Plugins
  4.  
  5. Here is my test function:
  6.  
  7. private const String SERVER = "localhost";
  8. private const String PORT = "5432";
  9. private const String USER = "postgres";
  10. private const String PASSWORD = "password";
  11. private const String DATABASE = "test";
  12.  
  13. public NpgsqlConnection connection = null;
  14.  
  15. // Use this for initialization
  16. void Start ()
  17. {
  18. connection = new NpgsqlConnection(
  19. "Server=" + SERVER + ";" +
  20. "Port=" + PORT + ";" +
  21. "User Id=" + USER + ";" +
  22. "Password=" + PASSWORD + ";" +
  23. "Database=" + DATABASE + ";"
  24. );
  25.  
  26. connection.Open();
  27.  
  28. NpgsqlCommand command = new NpgsqlCommand("SELECT name FROM test LIMIT 10", connection);
  29.  
  30. // Prepare the command.
  31. command.Prepare();
  32.  
  33. // Execute SQL command.
  34. NpgsqlDataReader dr = command.ExecuteReader();
  35.  
  36. while (dr.Read())
  37. {
  38. String TestName = dr.GetString(0);
  39. Debug.Log("Test Name : " + TestName);
  40. }
  41.  
  42. connection.Close();
  43. }
Add Comment
Please, Sign In to add comment