JarHead Posted December 9, 2004 Posted December 9, 2004 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! Quote
my_lou Posted December 10, 2004 Posted December 10, 2004 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'] Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.