Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ahotoon · Feb 21, 2019 at 11:36 PM · unity 2ddatabaseconnectionssl

help connect unity with postgresql database

hi

i want to connect my game to a database on Heroku server.

i wrote the code and it works when running in visual studio, the connection works and also the queries without errors, but when running from unity I get an error, I'll attach my code and the errors below.


 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Npgsql;
 using System.Data;
 
 public class DBConn : MonoBehaviour
 {
     private DataSet ds = new DataSet();
     private DataTable dt = new DataTable();
     List<string> dataItems = new List<string>();
     // Start is called before the first frame update
     void Start()
     {
         dataItems = SqlConn();
     }
 
     // Update is called once per frame
     void Update()
     {
         
     }
     public List<string> SqlConn()
     {
         string connstring = String.Format("Server={0};Port={1};" +
           "User Id={2};Password={3};Database={4}?ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory",
           "host", "port", "userid",
           "password", "dbname");
 
         Debug.Log("Connect String = " + connstring);
         // Making connection with Npgsql provider
         NpgsqlConnection conn = new NpgsqlConnection(connstring);
                       Debug.Log("Connected");
         conn.Open();
          Debug.Log("after open");

         string sql = "SELECT * FROM webuser";
         NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);
         ds.Reset();
         da.Fill(ds);
         dt = ds.Tables[0];
         Debug.Log(dt);
         conn.Close();
         return dataItems;
     }
     }
 


the error

 NpgsqlException: FATAL: 28000: no pg_hba.conf entry for host "--", user "--", database "--?ssl=true", SSL off
 Npgsql.NpgsqlConnector.CheckErrors () (at <2f318a3bcab64a52b3458684e232b435>:0)
 Npgsql.NpgsqlConnector.Open () (at <2f318a3bcab64a52b3458684e232b435>:0)
 Npgsql.NpgsqlConnectorPool.GetPooledConnector (Npgsql.NpgsqlConnection Connection) (at <2f318a3bcab64a52b3458684e232b435>:0)
 Npgsql.NpgsqlConnectorPool.RequestPooledConnectorInternal (Npgsql.NpgsqlConnection Connection) (at <2f318a3bcab64a52b3458684e232b435>:0)
 Npgsql.NpgsqlConnectorPool.RequestPooledConnector (Npgsql.NpgsqlConnection Connection) (at <2f318a3bcab64a52b3458684e232b435>:0)
 Npgsql.NpgsqlConnectorPool.RequestConnector (Npgsql.NpgsqlConnection Connection) (at <2f318a3bcab64a52b3458684e232b435>:0)
 Npgsql.NpgsqlConnection.Open () (at <2f318a3bcab64a52b3458684e232b435>:0)
 (wrapper remoting-invoke-with-check) Npgsql.NpgsqlConnection.Open()
 DBConn.SqlConn () (at Assets/scripts/DBConn.cs:35)
 DBConn.Start () (at Assets/scripts/DBConn.cs:16)


i don't know what is wrong when i remove the ssl part i get the same error i've been struggling with it all day any help will be appreciated.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by LauraleeO · Apr 21, 2020 at 06:42 AM

Hi @ahotoon, I'm trying to do the same thing you're trying to do but I don't know where to start. Have you found a solution to insert a PostgreSQL database into Unity?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Duduck · Sep 28, 2020 at 10:57 AM

@ahotoon There is a "?" in the connstring which suppose to be ";" right between "Database={4}?ssl", although I spot that, I have other problem where it just spit out InvalidOperationException: Exception_Ssl_RequestError, which I can't find a real solution for it. If you and answer I will be greatly appreciated.,There is a "?" in the connstring which suppose to be ";" right between "Database={4}?ssl", although I spot that, I have other problem where it just spit out InvalidOperationException: Exception_Ssl_RequestError, which I can't find a real solution for it. If you and answer I will be greatly appreciated.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

173 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Firebase doesn't work on WiFi! Strange behavior 0 Answers

Unity connecting to AvtiveMQ server using SSL not start. 0 Answers

Error at database connection : SocketException: An address incompatible with the requested protocol was used. How do I solve it? 1 Answer

Not able to connect MS SQL to WebGL Program. 0 Answers

How to connect to an oracle database 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges