Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I have recently decided to make the switch from SQL server to PostgreSQL, however I am having issues making a connection to the server (basically, I have no idea what I'm doing). I simply want to make a connection to my server, without using the PostgreSQLDirect .Net Dataprovider (the one you have to pay for). I'm willing to use ODBC or anything, I need help!
Posted

connecting to PostgreSQL db using the ODBC .NET Data Provider is easy. First you'll have to install a PostgreSQL ODBC driver (maybe plsqlODBC) and then create a data source (under System Tools>Data Sources). Then in VB.NET you do this:

 

Imports System

Imports System.Date

Imports System.Data.Odbc

 

 

Private Sub Something()

 

Dim commonConnection As New OdbcConnection

Dim reader As New OdbcDataReader

 

commonConnection.ConnectionString = "DSN=datasourcename;UID=username;PWD=password"

 

'Open connection to an instance of the PostgreSQL database.

Try

commonConnection.Open()

Catch Ex As Exception

MsgBox(Ex.Message)

End Try

 

commonOdbcCommand = New OdbcCommand

commonOdbcCommand.Connection = commonConnection

commonOdbcCommand.CommandText = "Select * FROM DBTABLE"

 

Try

reader = commonOdbcCommand.ExecuteReader(CommandBehavior.Default)

Catch Ex As Exception

MsgBox(Ex.Message)

End Try 'End Try

 

If commonReader.HasRows Then

While commonReader.Read

'DO Something

End While

End If

 

commonOdbcCommand.Dispose()

 

commonConnection.Close()

 

End Sub

 

 

 

I have recently decided to make the switch from SQL server to PostgreSQL' date=' however I am having issues making a connection to the server (basically, I have no idea what I'm doing). I simply want to make a connection to my server, without using the PostgreSQLDirect .Net Dataprovider (the one you have to pay for). I'm willing to use ODBC or anything, I need help![/quote']

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...