Jump to content

[Answered] Postgre Connection By Vb.net Application


alevezzo

Recommended Posts

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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...