Ignas Ausiejus
Ignas Ausiejus

Reputation: 183

Connecting to postgresql on Visual Studio

I have an issue connecting to my local postgresql database. It seems like I retrieve all the tables and other information in my Server Explorer, but sadly everytime I compile I get an exception that says

An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
 Additional information: Keyword not supported: 'host'.

Here's my code

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBVSHotel
{
    class Program
    {
        static void Main(string[] args)
        {
            var con = new SqlConnection("User Id = postgres; Host = localhost; Database = Hotels; Initial Schema =public");
        }
    }
}

Upvotes: 5

Views: 46791

Answers (2)

ErikEJ
ErikEJ

Reputation: 41779

You need to use the Npgsql provider and new NpgsqlConnection, SqlConnection is for Microsoft SQL Server.

http://www.npgsql.org/doc/

Upvotes: 14

Gonay Pico
Gonay Pico

Reputation: 29

I think the problem is in the conection string (the word host is not a parameter)

connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
var con = new SqlConnection(connetionString);

Upvotes: 0

Related Questions