|
-
March 7th, 2006, 02:20 AM
#1
Establishing connection using ODBC
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.
-
March 7th, 2006, 02:49 AM
#2
Re: Establishing connection using ODBC
Like this?
Code:
using System.Data.Odbc;
OdbcConnection cn = new OdbcConnection("ConnectionString");
cn.Open();
/Leyan
-
March 7th, 2006, 06:33 AM
#3
Re: Establishing connection using ODBC
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.
-
March 7th, 2006, 06:58 AM
#4
Re: Establishing connection using ODBC
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.
-
March 7th, 2006, 07:36 AM
#5
Re: Establishing connection using ODBC
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.
-
March 7th, 2006, 07:55 AM
#6
Re: Establishing connection using ODBC
Well the problem is in the connectionstring somewhere....
Have a look at Connectionstrings to get help on how to compose it.
/Leyan
-
March 7th, 2006, 08:00 AM
#7
Re: Establishing connection using ODBC
Make sure that you have the PostgreSQL ODBC driver installed.
Or skip ODBC and try the npgSQL driver .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|