Click to See Complete Forum and Search --> : Establishing connection using ODBC
technowerk
March 7th, 2006, 01:20 AM
hi,
i'm trying to establish connection between my C# 2005 Express Edition application and the PostgreSQL server database on another machine on the same network using ODBC.
i'm new to this. So can somebody help me with the code to do this?
Any help will be highly appreciated.
thnx in advance.
Athley
March 7th, 2006, 01:49 AM
Like this?
using System.Data.Odbc;
OdbcConnection cn = new OdbcConnection("ConnectionString");
cn.Open();
/Leyan
technowerk
March 7th, 2006, 05:33 AM
thnx for ur quick reply Leyan.
I tried the same code to establish the connection with the database but it gives me an error saying "data source not found"
My code goes like this-
using System.Data.Odbc;
public OdbcConnection cn;
public OdbcDataAdapter da;
private void Form1_Load(object sender, EventArgs e)
{
OdbcConnection cn = new OdbcConnection("datasource=PostgreSQL Database Server 8.0;initial catalog=contact;uid=postgres;pwd=****");
OdbcDataAdapter da = new OdbcDataAdapter("select * from activity",cn);
cn.Open();
MessageBox.Show("Connection successful");
}
Can you pls help me with this error?
thnx once again.
stepi
March 7th, 2006, 05:58 AM
Hi there,
Your connection string should look like "DRIVER={PostgreSQL};SERVER=SERVER_IP_ADDRESS;DATABASE=YOUR_DATABASE_NAME; UID=postgres;PWD=PASSWORD_4_postgres";
Hope this will help.
technowerk
March 7th, 2006, 06:36 AM
thnx for your help. But the problem still remains. I tried the connection string as you suggested but it again gives me the same error saying
"{"ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"}".
Can you tell me why is this happening?
thnx once again.
Athley
March 7th, 2006, 06:55 AM
Well the problem is in the connectionstring somewhere....
Have a look at Connectionstrings (http://www.connectionstrings.com) to get help on how to compose it.
/Leyan
klintan
March 7th, 2006, 07:00 AM
Make sure that you have the PostgreSQL ODBC driver installed.
Or skip ODBC and try the npgSQL driver .
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.