* Makefile.am:
[monodevelop.git] / extras / MonoDevelop.Database / MonoDevelop.Database.Sql.Npgsql / NpgsqlConnectionProvider.cs
blobf0368e2ae32239e9d4e88ddcd29339381a6cbff2
1 //
2 // Authors:
3 // Christian Hergert <chris@mosaix.net>
4 // Ben Motmans <ben.motmans@gmail.com>
5 //
6 // Copyright (C) 2005 Mosaix Communications, Inc.
7 // Copyright (c) 2007 Ben Motmans
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
15 //
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
18 //
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 // THE SOFTWARE.
28 using System;
29 using System.Data;
30 using Npgsql;
31 using System.Collections.Generic;
32 namespace MonoDevelop.Database.Sql.Npgsql
34 public class NpgsqlConnectionProvider : AbstractConnectionProvider
36 public override IPooledDbConnection CreateConnection (IConnectionPool pool, DatabaseConnectionSettings settings, out string error)
38 string connStr = null;
39 try {
40 if (settings.UseConnectionString) {
41 connStr = settings.ConnectionString;
42 } else {
43 //User ID=root;Password=myPassword;Host=localhost;Port=5432;Database=myDataBase;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0;
44 connStr = String.Format ("User ID={0};Password={1};Host={2};Port={3};Database={4};",
45 settings.Username, settings.Password, settings.Server, settings.Port, settings.Database);
47 connStr = SetConnectionStringParameter (connStr, String.Empty, "Pooling", "false");
48 NpgsqlConnection connection = new NpgsqlConnection (connStr);
49 connection.Open ();
51 error = null;
52 return new NpgsqlPooledDbConnection (pool, connection);
53 } catch (Exception e) {
54 error = e.Message;
55 return null;