Jump to content

[Answered] Postgre Connection By Vb.net Application


Recommended Posts

Posted

Hi all, im new and i need some help.

I developed a vb.net application that use a database.

I sign in at heliohost and created my account then trought cpanel i create my database using postgre.

Now i have to connect my application to that database.

What is the correct connection string?

I used this string "host=inquadramentosorteggi.heliohost.org; user id =alevezzo_alevezzo86; password=[mypassword]; database=alevezzo_inquadramentosorteggi;"

Whats wrong? What i have to do?

With another database (mysql) on another host it work correctly but i need to use postgre.

Thaks for everyone give me some help.

Posted

Does it give you any useful error messages?

 

Also, another user had questions about connecting .NET to MySQL so I posted these test files for him. It will be fairly similar to connect to PostgreSQL so it might help you too.

Sorry for the delay in getting this posted. This is my test file that connects to MySql from .aspx and it works fine for me.

 

Default.aspx:

<%@ Page Language="VB" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "MySql.Data.MySqlClient" %>
<script language="VB" runat="server">

Sub Page_Load(sender As Object, e As EventArgs)

   Dim myConnection  As MySqlConnection
   Dim myDataAdapter As MySqlDataAdapter
   Dim myDataSet     As DataSet

   Dim strSQL        As String
   Dim iRecordCount  As Integer

   myConnection = New MySqlConnection("server=johnny.heliohost.org; user id=username_database;
       password=********; database=username_database; pooling=false;")

   strSQL = "SELECT * FROM username_database.people;"

   myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
   myDataSet = New Dataset()
   myDataAdapter.Fill(myDataSet, "people")

   MySQLDataGrid.DataSource = myDataSet
   MySQLDataGrid.DataBind()

End Sub

</script>

<!DOCTYPE html>
<html lang="en">
   <head>
       <meta charset="utf-8" />
       <title>ASP.NET MySQL Test</title>
   </head>
   <body>
       <div>
           <form runat="server">

<asp:DataGrid id="MySQLDataGrid" runat="server" />

           </form>
       </div>
   </body>
</html>

 

web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
<compilation>
<assemblies>
<add assembly="*"/>
</assemblies>
</compilation>

</system.web>
</configuration>

 

MySql.Data.dll:

http://area51.heliohost.org/MySql.Data.dll.gz

 

Test database:

mysql> select * from people;
+----+------------+-----------+
| id | first_name | last_name |
+----+------------+-----------+
|  1 | Jack       | Spratt    |
|  2 | Jill       | McHill    |
|  3 | Joe        | Schmoe    |
+----+------------+-----------+
3 rows in set (0.02 sec)

Posted

Thanks Kridos.

I just wroted MySql code and it works good.

Now i need to convert the connection string (and other things) to connect my application to the postgre database on heliohost.

The exception detected by my app is similar to "file not found" that i think means my app cant find the database.

I searched and founded an example on how to use postgre databases trough "npgsql.dll" but i think the real problem is just the connection string.

Thanks for your help

Posted

No problem. I'll flag it as answered then since it sounds like you're on the right track now. If you don't mind taking the time to post again it might be useful for others if you were to show us your postgresql connection code once it's working.

Posted

Adding mono.security.dll to my project now the connection work.

But now i have another problem and i cant find the solution (with mysql was all simpler!!!)

This is the error: "permission denied for relation [tablename]" "Code: 42501"

I have all permission on that database so why that query dont work?

What i have to do?

Thanks

 

I did it!

To connect database u have to insert mono.security.dll.

Then u have to give all permission to the user is connecting to the database manually because is not as default.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...